|
-
July 13th, 2012, 08:40 AM
#8
Re: Passing UDT from VB 6.0 to C++ DLL
 Originally Posted by user65536
here is the DLL info.
Code:
extern "C" __declspec(dllexport) int GetHash(HASHINFO*);
Code:
typedef struct {
unsigned char* pHash; // Address of buffer for saving hash
unsigned char* szPassword; // Password
int nPasswordLen; // Password length
unsigned char* szSalt; // Salt
int nSaltLen; // Salt length
unsigned char* szName; // User name
int nNameLen; // User name length
DWORD dwFlags; // Flags
} HASHINFO;
Here is the VB
Code:
Private Type HASHINFO
hash As String
szPassword As String * 10
nPasswordLen As Long
szSalt As String * 10
nSaltLen As Long
szName As String * 10
nNameLen As Long
dwFlags As Long
End Type
Private Declare Sub GetHash Lib "c:\md5\md5.dll" (ByRef pudt As HASHINFO)
Code:
Private Sub Command1_Click()
Dim udt As HASHINFO
udt.hash = vbNullString
udt.szPassword = "test" & Chr(0)
udt.nNameLen = 4
udt.szSalt = "test" & Chr(0)
udt.nSaltLen = 4
udt.szName = "test" & Chr(0)
udt.nNameLen = 4
udt.dwFlags = 0
Call GetHash(udt)
End Sub
I just get a crash.
Anyone out there to help me?
What jumps out at me first is that the DLL UDT structure given above says (for the hash string) "Address of buffer for saving hash". That to me means it's a reference to the memory where the string is stored, not the actual string itself. If true, then might the VB UDT structure use a Long, not a string? Whichever it is, the other string members would be the same, no?
So basically, if the hash member and the string members are of the same type, you can't make them different in VB. They either have to both be fixed length strings, or variable length strings.
Incidentally, VB pads fixed length strings with zeros (Chr$(0) or vbNullChar) if you don't assign all the available characters. The value returned by Len(TheUDT) will always be the length of the structure in memory. When fixed length strings are defined in a UDT, the actual string is stored in the space allocated for the structure, thus will be included in the value returned by Len. On the other hand, variable length strings are not stored within the space in memory for the structure, because the string member is a reference to the location of the string, not the actual string.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|