VB.NET Marshalling

M

Mike

Folks,

I have a C/C++ Win32 based SDK API DLL with VB support. I'm now
converting to VB.NET and I am wondering about how to properly marshall
the type structures.

For example, I have these

typedef struct tagTUserInfo {
DWORD Id;
char Name[SIZE_USER_NAME];
char Title[SIZE_USER_TITLE];
} TUserInfo;

typedef struct tagTUser {
DWORD Status;
TUserInfo Info;
char Password[SIZE_PASSWORD];
char Security[NUM_USER_SECURITY][SIZE_SECURITY_NAME];
} TUser;

In VB, the structures are:

type TUserInfo
Id as Long
Name as String*SIZE_USER_NAME
Title as String*SIZE_USER_TITLE
end type

type TUser
Status as Long
Info as TUserInfo
Password as String*SIZE_PASSWORD
Security(1 to NUM_USER_SECURITY) as String*SIZE_SECURITY_NAME
end type

I have these type structures in a VB.NET module:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)>
Public Structure TUserInfo
Public ID As Integer
<MarshalAs(UnmanagedType.ByValTStr,SizeConst:=SIZE_USER_NAME)>
Public Name As String
<MarshalAs(UnmanagedType.ByValTStr,SizeConst:=SIZE_USER_TITLE)>
Public Title As String
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)>
Public Structure UserSecurityProfiles
<MarshalAs(UnmanagedType.ByValTStr,sizeconst:=SIZE_SECURITY_NAME)>
Public Name As String
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)>
Public Structure TUser
Public Status As Integer
Public Info As TUserInfo
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=SIZE_PASSWORD)>
Public Password As String
<MarshalAs(UnmanagedType.ByValArray,sizeconst:=NUM_USER_SECURITY)>
Public Security() As UserSecurityProfiles
End Structure

These seem to work for INPUT (reading structures) but I am not sure
about OUTPUT (writing structure)

For example, we have a wcAddUser(TUser &user) API function. My
question is will VB.NET marshaling handle the proper structures
writing back?

I ask because in VB, we have a WCVB.DLL wrapper dll that does the
C/BASIC variant conversion for the wcAddUser() call.

I'm wondering if I can do away with our WCVB.DLL wrapper since it did
for VB what VB.NET now seems to do for you.

Correct? Tips? Comments?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top