I am writing this only after exhausting effort to search and find the solution was unsuccessful.
I am using Visual Studio 2005. The Test123 function written in C++ should be called from vb.net by using Interop Services.
The Testing.dll is a CLR dll.
Below is a simplified version of the C++ structure :
typedef struct TEST_STRUCT
{
long lTotal;
int nRow;
int nCol;
CString sName;
BOOL bFound;
int item[100];
} TEST;
Below is a simplified version of the structure declared in vb.net :
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Ansi)> _ Public Structure TEST_STRUCT ' ''<System.Runtime.InteropServices.FieldOffsetAttribute(0)> _ Public lTotal As Integer Public nRow As Integer Public nCol As Integer <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)> _ Public sName As String <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> _ Public bFound As Boolean '<System.Runtime.InteropServices.MarshalAsAttribute _ '(System.Runtime.InteropServices.UnmanagedType.SafeArray, SafeArraySubType:=Runtime.InteropServices.VarEnum.VT_I4)> _ <System.Runtime.InteropServices.MarshalAsAttribute _ (System.Runtime.InteropServices.UnmanagedType.LPArray, SizeConst:=100)> _ Public Item() As Integer End Structure Public Declare Auto Function Test123 Lib "Testing.dll" () As TEST_STRUCT
What can work :
1) I can call the module Test123 from vb.net and it can run.
2) I can interop data for lTotal, nRow and nCol and receive at vb.net without any problem.
What my questions are :
1) How to interop data for sName, bFound and item[100]?
2) Which part I am wrong?
3) How should I declare the structure in vb.net to interop these data?
4) Can Interop support CString directly?
5) Is there any indirect way of marshaling which can work, such as doing the Interop in C# and then call from vb.net?
Your guidance on solving this problem is very much appreciated.
Thanks,
Goutam

New Topic/Question
Reply




MultiQuote




|