How To Pass Array of UDTs with Variable Length Strings to C/C++ (194609)
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows 5.0
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q194609 SUMMARY
When you are working with an array of User-Defined types (UDTs) in Visual
Basic, you may want to pass the array to a C/C++ DLL. However, the array
cannot be passed directly because SAFEARRARYs are limited to Automation-
safe data types, and a UDT is not a standard Automation data type.
Moreover, if the UDT contains variable length strings, you cannot pass a
pointer to the first member of the array because Visual Basic will create a
temporary copy of the member in order to handle normal UNICODE to ANSI
conversion of strings.
This article demonstrates one way to bypass these problems and successfully
pass an array of UDTs with variable length strings to C/C++ DLLs.
REFERENCES
For detailed information on how to create a C DLL and use it in Visual
Basic, please see the following articles:
"DLLs for Beginners" in the Microsoft Developer Network (MSDN) Library
"VB5DLL.DOC" located on the VB5 CD-ROM in the "Tools\Docs" directory
For more information on using a type library to declare C/C++ functions in
Visual Basic, see the following article in the Microsoft Knowledge Base:
189133
: How To Make C DLL More Accessible to VB with a Type Library
For additional information, please see the following articles in the
Microsoft Knowledge Base:
142840
: Visual Basic Requirements for Exported DLL Functions
171583
: How To Fill a 32-bit VBA Array of UDType via a Visual C++ DLL
Modification Type: | Minor | Last Reviewed: | 7/1/2004 |
---|
Keywords: | kbcode kbDLL kbhowto kbString KB194609 |
---|
|