Results 1 to 2 of 2

Thread: VB - CGI Program

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    VB - CGI Program

    Very simple CGI program demonstating how to make a simple web page through code....

    Open a new project, remove the default form, add a BAS module, and put this code in the BAS module.
    From project properties, make sure the "Startup Object" is Sub Main

    Compile the project, and put the exe in the C:\Inetpub\Scripts directory
    Right click the exe and give propper permissions to the exe.

    Finally, open your browser, and type this: http://localhost/Scripts/MyCGI.exe (that is, if you named your exe MyCGI.exe, otherwise put whatever it's name is)
    VB Code:
    1. Option Explicit
    2.  
    3. Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
    4. Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
    5. Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, ByVal lpBuffer As String, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long
    6.  
    7. Public Const STD_INPUT_HANDLE = -10&
    8. Public Const STD_OUTPUT_HANDLE = -11&
    9. Public Const FILE_BEGIN = 0&
    10.  
    11. Public hStdIn As Long   ' handle of Standard Input
    12. Public hStdOut As Long  ' handle of Standard Output
    13.  
    14. Public Sub Main()
    15.     Dim Count As Long, Buff As String
    16.    
    17.     hStdIn = GetStdHandle(STD_INPUT_HANDLE)
    18.     hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)
    19.    
    20.     Send "HTTP/1.0 200 OK"
    21.     Send "Content-type: text/html" & vbCrLf
    22.    
    23.     Open App.Path & "\TestFile.txt" For Binary Access Read As #1
    24.         Buff = String(LOF(1), 0)
    25.         Get #1, , Buff
    26.         Count = Val(Buff) + 1
    27.     Close #1
    28.    
    29.     Open App.Path & "\TestFile.txt" For Binary Access Write As #1
    30.         Put #1, , CStr(Count)
    31.     Close #1
    32.    
    33.     Send "<html><body><h1>Hello world !</h1>"
    34.     Send "<br><br><br>"
    35.     Send "This page was loaded " & Count & " time" & IIf(Count = 1, "", "s") & "."
    36.     Send "</body></hrml>"
    37.    
    38.     End
    39. End Sub
    40.  
    41. Private Function Send(ByVal Str As String) As Long
    42.     Dim lBytesWritten As Long
    43.    
    44.     Str = Str & vbCrLf
    45.     WriteFile hStdOut, Str, Len(Str), lBytesWritten, ByVal 0&
    46.    
    47.     Send = lBytesWritten
    48. End Function
    Last edited by CVMichael; Apr 7th, 2004 at 09:14 PM.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    CGI - Input & Output

    The attached project is demostrating how to get user input, process it, and output.

    Did not put comments almost at all, but everything is very short and simple to understand.
    Attached Files Attached Files
    Last edited by CVMichael; Apr 7th, 2004 at 09:14 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width