BUG: Visual Basic App Crashes Passing UDT with String and EnumID: Q221101
|
If a Visual Basic application retrieves a User Defined Type (UDT) containing String and Enum fields from a C++ DLL, the Visual Basic application crashes on the call to the DLL file. No error message is displayed.
Use the Long data type instead of Enum in the Type declaration of the Visual Basic UDT.
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
#include <windows.h>
// the UDT declaration
enum VBenum
{
wf1 = 1,
wf8 = 8,
wf1e = 0x1E
};
typedef struct
{
char cArray[30];
VBenum lformat;
} mUDT;
// dll's export method
int _stdcall passUDT(mUDT* pU)
{
char* cp="hello, world!";
strncpy(pU->cArray, cp, 14);
pU->lformat = wf1e;
return 30;
}
; The DEF File
LIBRARY MyDll
EXPORTS
passUDT @1
Private Enum MyEnum
wf1 = &H1&
wf8 = &H8&
wf1e = &H1E&
End Enum
Private Type MyUDT1
myStr As String * 30
mL As MyEnum
End Type
Private Type MyUDT2
myStr As String * 30
mL As Long
End Type
Private Declare Function passUDT1 Lib "c:\MyDll\Debug\MyDll.dll" _
Alias "passUDT" (myU As MyUDT1) As Long
Private Declare Function passUDT2 Lib "c:\MyDll\Debug\MyDll.dll" _
Alias "passUDT" (myU As MyUDT2) As Long
' Visual Basic crashes on the call to passUDT1.
Private Sub Command1_Click()
Dim mU As MyUDT1
MsgBox passUDT1(mU)
MsgBox mU.myStr
End Sub
' Visual Basic works correctly on the call to passUDT2.
Private Sub Command2_Click()
Dim mU As MyUDT2
MsgBox passUDT2(mU)
MsgBox mU.myStr
End Sub
Additional query words: Structure
Keywords : kbDLL kbVBp400bug kbVBp500bug kbVBp600bug kbVC kbGrpVB
Version : WINDOWS:4.0,5.0,6.0
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: June 2, 1999