views:

397

answers:

2

These types come from the demos for FastCGI Dll Library (with SIGTERM handler) for Windows Web Servers and are written in PowerBASIC. I'm trying to convert them to VB6 (having also discovered how to call a CDECL DLL from VB6).

    ' Structures
    TYPE FCGX_STREAM
      pData           AS DWORD            ' Pointer to the first byte of data   
      LenStored       AS DWORD            ' Bytes Total data stored - up to 4.2GB 
      Capacity        AS DWORD            ' Bytes Total available   - up to 4.2GB  
      CurPos          AS DWORD            ' Current Position within the buffer of the next byte to read, as an offset from pData

      Reserved        AS STRING*12        ' Opaque Variables
    END TYPE ' 28 bytes  


    TYPE FCGX_REQUEST 
      Version         AS LONG             ' Dll Version Number * 1000 = %FCGI_VERSION        
      ReqCount        AS LONG             ' Request Counter 

      Role            AS LONG             ' FastCGI Role
      ConnFlags       AS LONG             ' Connection flags - zero = application closes connection after responding

      ReqMethod       AS LONG             ' Request HTTP Method - Code 1 - 8
      ContLen         AS LONG             ' CONTENT_LENGTH - Length of POST data sent (in the pInStream Data String)   
      pzQuery         AS ASCIIZ PTR       ' Pointer to ASCIIZ (Null Terminated) QUERY_STRING (Values Only) - Always a valid pointer

      nParam          AS LONG             ' Number of Request Params in the array                                  
      envp            AS DWORD PTR        ' Pointer to Array of Request Parameters  

      pIn             AS FCGX_STREAM PTR  ' Pointer to a String Builder object
      pOut            AS FCGX_STREAM PTR  ' Pointer to a String Builder object
      pErr            AS FCGX_STREAM PTR  ' Pointer to a String Builder object                                          

      pzLastErr       AS ASCIIZ PTR       ' Pointer to ASCIIZ String containing Last Error description

      Reserved        AS STRING*108       ' Opaque Variables
    END TYPE ' 160 bytes

My problem is in comprehending how to get at the information stored in ASCIIZ PTR, FCGX_STREAM PTR and DWORD PTR items.

+2  A: 

I haven't worked with VB6 in many years, so take the information below with a healthy dose of skepticism. But here's where I'd start, if I were faced with this problem today.

Since you're working in VB6, I'll assume that this is 32-bit code.

The PTR types appear to be pointers to blocks of memory that were allocated by something else. To access that memory, you need to dereference the pointer.

All of the PTR values are 32 bits, so when you create your VB6 structure for this, place DWORD or LONG or whatever the VB6 32-bit value is.

To dereference the pointers, you'll need to call the Windows API function RtlMoveMemory, as described here. All three of the parameters to RtlMoveMemory are 32-bit values.

Jim Mischel
+1. But never link to anything with RtlMoveMemory aliased as CopyMemory unless you credit Bruce McKinney :) http://support.microsoft.com/kb/129947
MarkJ
Can I recommend a link. Karl Peterson (VB6 guru) writes about dealing with pointers in structures in VB6 http://vb.mvps.org/articles/ap199911.asp
MarkJ
+1  A: 
  • Jim's answer looks good. I'd also suggest looking at the Microsoft advice on writing C DLLs to be called from VB. Originally released with VB5 but still relevant to VB6. It explains the structure packing etc.
  • EDIT. Also worth a look: VB6 guru Karl Peterson discusses how to deal with structures containing pointers in VB6.
MarkJ