| Prepared output is passed to the WriteSO function through the STD_OUTPUT_HANDLE, a constant to obtain the handle associated with standard output. The handle writes standard output to the web server when it is accessed via a URL. Definitions: hFile = Handle to the file to be written to. lpBuffer Pointer to the buffer containing the data to be written to the file. nNumberOfBytesToWrite = Number of bytes to write to the file. lpNumberOfBytesWritten = Pointer to the number of bytes written by this function call. lpOverlapped = Pointer to an OVERLAPPED structure, telling the file access functions what part of a file to read or write when asynchronous. ---Code Sample--- Option Explicit 'Windows API Functions needed for proces ' sing stdin and WriteSO Private Declare Function GetStdHandle Lib "Kernel32" ( _ ByVal nStdHandle As Long) As Long 'Get requested data using a writefile, the post method requires a call to readfile Private Declare Function WriteFile Lib "Kernel32" ( _ ByVal hFile As Long, _ ByVal lpBuffer As Any, _ ByVal nNumberOfBytesToWrite As Long, _ lpNumberOfBytesWritten As Long, _ lpOverlapped As Any) As Long ' Constants needed by the Windows API functions Private Const STD_INPUT_HANDLE = -10& Private Const STD_OUTPUT_HANDLE = -11& Public Function WriteSO(strOutput As String) As Long Dim lngNumBytesWritten As Long 'on error resume next WriteSO = 0 WriteSO = WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), _ strOutput & vbCrLf, _ Len(strOutput) + 2, _ lngNumBytesWritten, _ ByVal 0&) End Function Sub Main() On Error GoTo EndMain Dim strHeaders As String Dim i strHeaders = "Content-type: text/html" & vbCrLf & vbCrLf & "<--VB CGI-->" & vbCrLf Do i = i + 1 If Environ(i) = "" Then Exit Do strHeaders = strHeaders & Environ(i) strHeaders = strHeaders & " " Loop WriteSO strHeaders EndMain: End End Sub |
CGI Template |
Freelance ASP PHP web development | Web developer India Web development India| Prayagasoft - web designer India, Ecommerce developer india, Ecommerce design