Article ID: 194609 - Last Review: July 1, 2004 - Revision: 2.1 How To Pass Array of UDTs with Variable Length Strings to C/C++This article was previously published under Q194609 On This PageSUMMARY
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. MORE INFORMATION
The solution provided here relies on the type library to prevent Visual
Basic from copying the content of the array to the temporary space and
transforming the strings between ANSI and UNICODE. See the REFERENCES
section below for more information on this topic.
The UDT in this sample is: Step-by-Step Example - Create the DLL and Type Library
Step-by-Step Example - The Visual Basic Client App
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
(http://support.microsoft.com/kb/189133/EN-US/
)
: 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
(http://support.microsoft.com/kb/142840/EN-US/
)
: Visual Basic Requirements for Exported DLL Functions
171583 (http://support.microsoft.com/kb/171583/EN-US/ ) : How To Fill a 32-bit VBA Array of UDType via a Visual C++ DLL APPLIES TO
| Article Translations
|
Back to the top
