Quantcast
Channel: VBForums - API
Viewing all articles
Browse latest Browse all 168

Questions about STARTUPINFO structure in VB6

$
0
0
Since VB6 is a bit quirky with userdefined types, and all the rules it has for handling them internally, while the results withing VB6 might appear fine, when passing a UDT to another process like an API dll file, things might not be as fine as you think, and this makes them not 100% equivalent to the more standard concept of a "struct" in VC++ (which is how you will usually see structures being defined in online documentation). I have yet to find an official Microsoft documentation for how the STARTUPINFO structure should be defined as a UDT in VB6.

For example, in STARTUPINFO structure the fields lpReserved, lpDesktop, and lpTitle are all pointers to strings. So should I define these As Long when making a userdefined type in VB6, so that the fields will represent 32bit pointers? Or should I define them As String, and assume that VB6 will convert them to pointers when passing the STARTUPINFO structure to the CreateProcess API function that I'm trying to use? Same thing with the 3 fields wShowWindow, cbReserved2, and lpReserved2. First 2 of these fields are defined As Integer and the 3rd one As Byte according to someone's posting at http://stackoverflow.com/questions/2...ce-it-finishes but there is a problem here. Are these really supposed to be 2byte and 1byte fields as shown? Or are they supposed to be 4byte fields that represent pointers to 2byte and 1byte data fields? And if they are supposed to be 4byte pointers, but they are defined As Integer (2bytes) and As Byte (1byte), will VB6 automatically convert them to 4byte pointers when it passes the STARTUPINFO UDT to the CreateProcess API function?

Here's an idea of the confusion I'm having.

Here's how one person defined the STARTUPINFO structure on the above mentioned webpage.
Code:

Private Type STARTUPINFO
        cb              As Long
        lpReserved      As Long
        lpDesktop      As Long
        lpTitle        As Long
        dwX            As Long
        dwY            As Long
        dwXSize        As Long
        dwYSize        As Long
        dwXCountChars  As Long
        dwYCountChars  As Long
        dwFillAttribute As Long
        dwFlags        As Long
        wShowWindow    As Integer
        cbReserved2    As Integer
        lpReserved2    As Byte
        hStdInput      As Long
        hStdOutput      As Long
        hStdError      As Long
End Type


But here's how it's defined in ApiViewer2004.
Code:

Private Type STARTUPINFO
        cb As Long
        lpReserved As Long
        lpDesktop As Long
        lpTitle As Long
        dwX As Long
        dwY As Long
        dwXSize As Long
        dwYSize As Long
        dwXCountChars As Long
        dwYCountChars As Long
        dwFillAttribute As Long
        dwFlags As Long
        wShowWindow As Integer
        cbReserved2 As Integer
        lpReserved2 As Byte
        hStdInput As Long
        hStdOutput As Long
        hStdError As Long
End Type


Notice the differences in how some of the fields are defined. These differences will produce definite differences in the size of the structure, which will change the value that I need to supply to the cb field before passing the structure to the CreateProcess API function. And only one of these 2 is correct. Or it might be that neither of them is correct, and there might be a 3rd way of defining it that is actually correct. I really am going to need some help here with this.

Viewing all articles
Browse latest Browse all 168

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>