Yosi,
In C#, you would declare CALL_GDS like this:
[StructLayout(LayoutKind.Sequential)]
public struct CALL_GDS
{
public int ModuleId;
public int CPUid;
public int argc;
public IntPtr argv;
}
You would then declare getDatabase as so:
[DllImport("some.dll")]
public static extern void getDatabase(ref CALL_GDS mStruct);
To get the last array, you will have to handle the marshalling yourself.
You will want to do something like this (after you make the call):
// The structure.
CALL_GDS callGds = new CALL_GDS();
// Make the call.
getDatabase(ref callGds);
// The pointer to the string.
IntPtr stringPointer = IntPtr.Zero;
// The array of items in argc. Preallocate.
string[] argv = new string[callGds.argc];
// Cycle through the number of arguments.
for (int index = 0; index < callGds.argc; ++index)
{
// Get the IntPtr corresponding to the index position.
stringPointer = new IntPtr(callGds.argV.ToInt64() + (index *
IntPtr.Size));
// Marshal the string.
argv[index] = Marshal.PtrToStringAnsi(stringPointer);
}
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
I want to access a function implemented in a C-dll with the following
prototype:
getDatabase(CALL_GDS *mStruct)
typedef struct _CALL_GDS {
int ModuleId;
int CPUid;
int argc;
char **argv;//*argv[]
} CALL_GDS;
Now:
1. How would the CALL_GDS (and "char** argv") part look like in the
corresponding
C# prototype?
2. How do I call this C# method ?
Any idea?
C#:
[ StructLayout( LayoutKind.Sequential )]
public struct CALL_GDS
{
public int ModuleId;
public int CPUid;
public int argc;
[MarshalAs(UnmanagedType.ByValArray)]
public IntPtr argv;// pptr //*argv[]
}