Article ID: 194609
Article Last Modified on 7/1/2004
Type TestUDT
l As Long
str As String
End Type
#include <windows.h>
#include <oleauto.h>
struct tagTestUDT
{
long l;
BSTR str;
} TestUDT;
void __stdcall ModifyStruct(struct tagTestUDT *t, long nTotalItem)
{
// modify the last element
long i = nTotalItem - 1; // the array begins from 0
(t+i)->l = 200;
SysFreeString((t+i)->str ); // free the string passed in
(t+i)->str = SysAllocString(OLESTR("Changed."));
}
EXPORTS
ModifyStruct
[
uuid(D6229080-2CC3-11d2-9FD8-00C04F8EF4D4),
helpstring("Pass Array of UDTs Helper")
]
library PassUDTLib
{
//definition of the UDT
typedef struct tagTestUDT
{
long l;
BSTR str;
}TestUDT;
[
helpstring("test"),
dllname("UDTArray.dll")
]
module structDLL
{
[
helpstring("Modify the elements of array"),
entry("ModifyStruct")
]
void _stdcall ModifyStruct
(
[in, out] TestUDT* t,
[in] long nTotalItem
);
};
};
Private Sub Command1_Click()
' Note: You do not need to redefine TestUDT because it is in
' the type library we added to our project.
Dim t(0 To 1) As TestUDT
Dim i as long
t(0).l = 1
t(0).str = "test1"
t(1).l = 2
t(1).str = "Test2"
i = UBound(t) - LBound(t) + 1
ModifyStruct t(0), i 't(0)'s address will be passed to C
MsgBox "t(1).l = " & t(1).l & vbCrLf & "t(1).str = " & t(1).str
End Sub
189133 : How To Make C DLL More Accessible to VB with a Type Library
142840
: Visual Basic Requirements for Exported DLL Functions
171583
: How To Fill a 32-bit VBA Array of UDType via a Visual C++ DLL
Keywords: kbhowto kbdll kbstring kbcode KB194609