T
Tobias
Hi!
I have a problem which is quite tricky.
I need to pass a struct from .NET to a native Win32 DLL.
But i just need to pass the pointer to a reference of that struct.
With my first struct this worked pretty well, accepting to write
unsafe code ;-)
But my next struct has an array inside and I don't get it passed over
to the DLL correctly.
Here my struct in c#:
[StructLayout(LayoutKind.Sequential)]
unsafe public struct SDKNavInfo
{
public System.UInt32 size;
public TSDKPosition Pos;
[..]
//this is the relevant array!!
public System.UInt32[] PreviousManover;
[..]
}
My DLL Import looks like this (this can not be changed by myself):
[DllImport("SDK")]
unsafe private extern static int GetGuidanceInformation(TGPSData *
GPSData, System.Int32 forecast, ref SDKNavInfo *
NavigationInformation);
And this is the corresponding code where I try to call the function:
//method declared unsafe because of use of pointers and reference
private unsafe void btnCalcRoute_Click(object sender, System.EventArgs
e)
{
[..]
SDKNavInfo NavInfo = new SDKNavInfo();
[..]
SDKNavInfo * pNavInfo = &NavInfo;
GetGuidanceInformation(null, 0, ref pNavInfo);
}
Calling the GetGuidanceInformation function results in an error where
the debugger says (sorry for the translation, I get it in german!)
"parameter#3 can not be marshalled. Pointer can not point to
marshalled structures. Use byref instead."
I don't get it...what does it mean? Or even better, how can I fix this
problem??
Thanks in advance for your help
cheerz
Tobias
I have a problem which is quite tricky.
I need to pass a struct from .NET to a native Win32 DLL.
But i just need to pass the pointer to a reference of that struct.
With my first struct this worked pretty well, accepting to write
unsafe code ;-)
But my next struct has an array inside and I don't get it passed over
to the DLL correctly.
Here my struct in c#:
[StructLayout(LayoutKind.Sequential)]
unsafe public struct SDKNavInfo
{
public System.UInt32 size;
public TSDKPosition Pos;
[..]
//this is the relevant array!!
public System.UInt32[] PreviousManover;
[..]
}
My DLL Import looks like this (this can not be changed by myself):
[DllImport("SDK")]
unsafe private extern static int GetGuidanceInformation(TGPSData *
GPSData, System.Int32 forecast, ref SDKNavInfo *
NavigationInformation);
And this is the corresponding code where I try to call the function:
//method declared unsafe because of use of pointers and reference
private unsafe void btnCalcRoute_Click(object sender, System.EventArgs
e)
{
[..]
SDKNavInfo NavInfo = new SDKNavInfo();
[..]
SDKNavInfo * pNavInfo = &NavInfo;
GetGuidanceInformation(null, 0, ref pNavInfo);
}
Calling the GetGuidanceInformation function results in an error where
the debugger says (sorry for the translation, I get it in german!)
"parameter#3 can not be marshalled. Pointer can not point to
marshalled structures. Use byref instead."
I don't get it...what does it mean? Or even better, how can I fix this
problem??
Thanks in advance for your help
cheerz
Tobias