Thanks for the info... i looked at that information but
there is not much that will help me solve my problem which
is:
I have to pass an array of strings inside a structure,
from .NET code to a 'C' DLL, though i am able to pass the
structure.. the c code gives me garbage values for that
array.
the .NET code is:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)
Dim ErrorValue As Double
Dim FieldNumber As Integer
Dim Dummy As Integer
Public ControlNames() As String
End Structure
The "ControlNames" array is an array of 15 strings with
each string being 50 characters long.
and the 'C' structure which takes the values is:
struct Test { double ErrorValue;
int FieldNumber;
int Dummy;
char sFixUpCtrl[15][50];
};
This one is a little problematic... Normally, a fixed length array or
string in side of a structure is not a problem... For example, if it
was a single 50 character string:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure Test
Public ErrorValue As Double
Public FieldNumber As Integer
Public Dummy As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public sFixUpCtrl As String
End Structure
But your's is a fixed two dimensional array. I have never had that
come up before, and I really don't see a good way to do it with in the
bounds of what is currently defined in the framework...
As a work around (unless someone comes up with a better idea, or knows a
way to do this directly), I would suggest just passing a single string
buffer big enough to hold the entire thing, and then chunk the data on
the return. In theory that should work since arrays are just contiguos
blocks of memory - even if they are 2D. So maybe something like (you
may have to play with the numbers - I'm sort of sleepy right now
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure Test
Public ErrorValue As Double
Public FieldNumber As Integer
Public Dummy As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=750)> _
Public sFixUpCtrl As String
End Structure
And then, just do something like:
'Call your api call
Dim st As Test
.....
' chunk the string
Dim s(14) As String
For i As Integer = 0 To 14
s(i) = st.sFixUpCtrl.SubString(i*50, 50)
Next i
Oi! I'm getting sleepy... I hope I'm not doing something stupid in the
above little loop. But anyway, it's an idea that may work. I'll see if
I can find any more info on this tomorrow...