Results 1 to 5 of 5

Thread: VB6 DLL with IIS

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Location
    atlanta, ga
    Posts
    3

    Question VB6 DLL with IIS

    Question: I have wrote a few VC++ Win32 Console apps which I can use ISAPI. I want to do the same with VB but because of the lack of a true console app I want to see if I can do it using DLL's but don't know where to start if someone and point me in the right direction.

    Jason MItchell

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    VB can make console apps - just use AllocConsole and FreeConsole (which you won't even need to run as CGI). However, VB cannot make the standard DLLs needed for ISAPI - it can make ASP / COM components, or CGI executables.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Location
    atlanta, ga
    Posts
    3
    VB can make console apps but it has to open it's own console window.
    http://www.vb-world.net/api/console/

    The only problem with this technique is that it uses its own console. That is, if you call the app from one console (command prompt) the app will create another console, which prevents the VB app from returning information to the calling console.

    This problem stems from VB not supporting standard I/O (STDIO). Even using the Windows API, VB still cannot return information through STDIO.

    If you have a need to return information to an older application (one that requires STDIO), then this option will not work for you.

  4. #4
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    There's a GetStdHandle API call you can use to get the STDIO handles, then use ReadFile and WriteFile to work with the STDIO handle.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const STD_ERROR_HANDLE As Long = -12&
    4. Private Const STD_INPUT_HANDLE As Long = -10&
    5. Private Const STD_OUTPUT_HANDLE As Long = -11&
    6.  
    7. Private Const GENERIC_WRITE As Long = &H40000000
    8. Private Const FILE_SHARE_READ As Long = &H1&
    9. Private Const OPEN_ALWAYS As Long = 4&
    10. Private Const FILE_ATTRIBUTE_ARCHIVE As Long = &H20&
    11.  
    12. Private Const FILE_END As Long = 2&
    13.  
    14. Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
    15.  
    16. Private Declare Function WriteFile Lib "kernel32.dll" (ByVal hFile As Long, _
    17.     lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, _
    18.     lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long
    19.    
    20. Private Declare Function CreateFile Lib "kernel32.dll" Alias "CreateFileA" _
    21.     (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
    22.     ByVal dwShareMode As Long, lpSecurityAttributes As Any, _
    23.     ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _
    24.     ByVal hTemplateFile As Long) As Long
    25.    
    26. Public Declare Function SetFilePointer Lib "kernel32.dll" (ByVal hFile As Long, _
    27.     ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, _
    28.     ByVal dwMoveMethod As Long) As Long
    29.  
    30. Private Declare Function GetStdHandle Lib "kernel32" _
    31.     (ByVal nStdHandle As Long) As Long
    32.    
    33. Private Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" _
    34.     (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long
    35.  
    36. Private Declare Function AllocConsole Lib "kernel32" () As Long
    37. Private Declare Function FreeConsole Lib "kernel32" () As Long
    38.  
    39. Public Sub Main()
    40.     Dim STDOUT As Long 'handle to standard output
    41.     Dim strHTTP As String 'data buffer for HTTP header output
    42.     Dim strBuffer As String 'data buffer for writing to the log file
    43.     Dim lngBytesWritten As Long 'the number of bytes that were written
    44.     Dim retval As Long 'API return value
    45.     Dim FILEOUT As Long 'handle to the file to log to
    46.     'CGI Variables
    47.     Dim strQueryString As String
    48.     Dim strRemoteAddr As String
    49.     Dim strHTTPUserAgent As String
    50.    
    51.     'fill the buffers with nothing
    52.     strQueryString = Space$(256)
    53.     strRemoteAddr = strQueryString
    54.     strHTTPUserAgent = strQueryString
    55.    
    56.     'get and store the CGI variables needed
    57.     retval = GetEnvironmentVariable("QUERY_STRING", strQueryString, 256)
    58.     strQueryString = Left$(strQueryString, retval)
    59.     retval = GetEnvironmentVariable("REMOTE_ADDR", strRemoteAddr, 256)
    60.     strRemoteAddr = Left$(strRemoteAddr, retval)
    61.     retval = GetEnvironmentVariable("HTTP_USER_AGENT", strHTTPUserAgent, 256)
    62.     strHTTPUserAgent = Left$(strHTTPUserAgent, retval)
    63.    
    64.     strHTTP = "Location: ./win2000.gif" & vbCrLf & vbCrLf
    65.    
    66.     'start the console
    67.     'retval = AllocConsole 'UNCOMMENT FOR IDE DEBUGGING
    68.    
    69.     'get the handle to standard output
    70.     STDOUT = GetStdHandle(STD_OUTPUT_HANDLE)
    71.    
    72.     'write the string to STDOUT, just like writing to a file
    73.     retval = WriteFile(STDOUT, ByVal strHTTP, Len(strHTTP), lngBytesWritten, ByVal 0&)
    74.  
    75.     'close the handle to standard out
    76.     retval = CloseHandle(STDOUT)
    77.    
    78.     'close the console
    79.     'retval = FreeConsole 'UNCOMMENT FOR IDE DEBUGGING
    80.    
    81.     'open the file for writing
    82.     FILEOUT = CreateFile("C:\Inetpub\wwwroot\Test\image.log", GENERIC_WRITE, FILE_SHARE_READ, _
    83.         ByVal 0&, OPEN_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, 0)
    84.    
    85.     'if error
    86.     If FILEOUT = -1 Then Exit Sub
    87.        
    88.     'fill the buffer
    89.     strBuffer = Now & ";" & strQueryString & ";" & strRemoteAddr & ";" & strHTTPUserAgent & vbCrLf
    90.        
    91.     'move the file pointer to EOF
    92.     retval = SetFilePointer(FILEOUT, 0, 0, FILE_END)
    93.    
    94.     'write the buffer to the file
    95.     retval = WriteFile(FILEOUT, ByVal strBuffer, Len(strBuffer), lngBytesWritten, ByVal 0&)
    96.        
    97.     'close the handle to the file
    98.     retval = CloseHandle(FILEOUT)
    99. End Sub
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Location
    atlanta, ga
    Posts
    3
    That's that worked great.

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