Reputation: 812
I have a 3rd party DLL containing the following function:
SDK_API FunctionInQuestion(char* name, myStruct table[row][column]);
I'm pretty sure this function WILL modify myStruct table[row][column].
I need to call this from .net, here is how I tried (the used language is VB.NET, but if you know how to do it in C# thats not a problem, I'm pretty sure the principles are the same)
<System.Runtime.InteropServices.DllImportAttribute("dllinquestion.dll", EntryPoint:="FunctionInQuestion", CallingConvention:=Runtime.InteropServices.CallingConvention.Cdecl)> _
Public Shared Function FunctionInQuestion(ByVal name As System.Text.StringBuilder, ByRef table()() As myStruct) As Integer
End Function
myStruct C:
typedef struct
{
unsigned short int x;
unsigned short int y;
}myStruct;
myStruct .net:
<Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> _
Public Structure myStruct
Public x As UShort
Public y As UShort
End Structure
I've been Googling/searching Stackoverflow for a couple hours now and tried every 'solution' thus far, but I haven't been able to make it work. Please if you redirect/vote to close the question, I beg you to first look at the other question. If it's really a marshalling of a 2D struct array AND you are sure the question contains an answer, then please by all means close this, all the better.
Upvotes: 1
Views: 165
Reputation: 612884
You should marshal this as a simple linear array. I'm more familiar with C#, but in VB I think it would run like this:
ByVal table() As myStruct
Then you'll need to perform the 2D to 1D indexing conversion manually in the .net code.
Upvotes: 1