HttpCreateForm Function  
 
HFORM WINAPI HttpCreateForm(
  LPCTSTR lpszAction,  
  UINT nFormMethod,  
  UINT nFormType,  
  DWORD dwReserved  
);

The HttpCreateForm function creates a new form and returns a handle for use with the other form-related functions.

Parameters

lpszAction
A pointer to a string which specifies the name of the resource that the form data will be submitted to. Typically this is the name of a script that is executed on the server.
nFormMethod
An unsigned integer value which specifies how the form data will be submitted to the server. This parameter may be one of the following values:
Value Description
HTTP_METHOD_DEFAULT The form data should be submitted using the default method, using the GET command.
HTTP_METHOD_GET The form data should be submitted using the GET command. This method should be used when the amount of form data is relatively small. If the total amount of form data exceeds 2048 bytes, it is recommended that the POST method be used instead.
HTTP_METHOD_POST The form data should be submitted using the POST command. This is the preferred method of submitting larger amounts of form data. If the total amount of form data exceeds 2048 bytes, it is recommended that the POST method be used.
nFormType
An unsigned integer value which specifies the type of form and how the data will be encoded when it is submitted to the server. This parameter may be one of the following values:
Value Description
HTTP_FORM_DEFAULT The form data should be submitted using the default encoding method.
HTTP_FORM_ENCODED The form data should be submitted as URL encoded values. This is typically used when the GET method is used to submit the data to the server.
HTTP_FORM_MULTIPART The form data should be submitted as multipart form data. This is typically used when the POST method is used to submit a file to the server. Note that the script must understand how to process multipart form data if this form type is specified.
dwReserved
A reserved parameter. This value must be zero.

Return Value

If the function succeeds, the return value is a handle to the virtual form. If the function fails, the return value is INVALID_FORM. To get extended error information, call HttpGetLastError.

Remarks

The HttpCreateForm function is used to create a new form that will be populated with values and then submitted to the server for processing. When the form is no longer needed, it should be destroyed using the HttpDestroyForm function.

Example

HFORM hForm = INVALID_FORM;
HGLOBAL hgblResult = (HGLOBAL)NULL;
DWORD cbResult = 0;
INT nResult = 0;

hForm = HttpCreateForm(_T("/login.php"), HTTP_METHOD_POST, HTTP_FORM_ENCODED);

if (hForm == INVALID_FORM)
    return;

HttpAddFormField(hForm, _T("UserName"), lpszUserName, (DWORD)-1L, 0);
HttpAddFormField(hForm, _T("Password"), lpszPassword, (DWORD)-1L, 0);

nResult = HttpSubmitForm(hClient, hForm, &hgblResult, &cbResult, 0);
HttpDestroyForm(hForm);

if (hgblResult != NULL)
{
    LPBYTE lpBuffer = (LPBYTE)GlobalLock(hgblResult);

    // lpBuffer points to data returned by the server after the form
    // data was submitted

    GlobalUnlock(hgblResult);
    GlobalFree(hgblResult);
}

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools11.h
Import Library: cshtpv11.lib
Unicode: Implemented as Unicode and ANSI versions

See Also

HttpAddFormField, HttpAddFormFile, HttpClearForm, HttpDeleteFormField, HttpDestroyForm, HttpSubmitForm