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
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