G
Guest
Hi, I have a C# program that uses an unmanaged dll that has a function
similar to the signature below :
void f(out MyStruct[] arr, out int num); // num = actual array length returned
The array must be allocated (with known max length = 10) before the call to
the dll function (the dll just fills it ,with no allocations).
The definitions of Mystruct and :
public struct Mystruct TimeTag
{
Int32 Id;
Int32 Type;
TimeTag StartTime;
TimeTag EndTime;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
Int32[] Reserved;
}
public struct TimeTag
{
int Day;
Int Hour;
}
I allocate the array , init all fields , allocate and init all needed struct
fields , pass it to the dll and get an exception:
"The runtime has encountered a fatal error. The address of the error was at
0x79e95b95, on thread 0x28348. The error code is 0xc0000005. This error may
be a bug in the CLR or in the unsafe or non-verifiable portions of user code.
Common sources of this bug include user marshaling errors for COM-interop or
PInvoke, which may corrupt the stack".
I can't change nor the dll neither it's API.
What is the problem and what should I do to avoid it?
similar to the signature below :
void f(out MyStruct[] arr, out int num); // num = actual array length returned
The array must be allocated (with known max length = 10) before the call to
the dll function (the dll just fills it ,with no allocations).
The definitions of Mystruct and :
public struct Mystruct TimeTag
{
Int32 Id;
Int32 Type;
TimeTag StartTime;
TimeTag EndTime;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
Int32[] Reserved;
}
public struct TimeTag
{
int Day;
Int Hour;
}
I allocate the array , init all fields , allocate and init all needed struct
fields , pass it to the dll and get an exception:
"The runtime has encountered a fatal error. The address of the error was at
0x79e95b95, on thread 0x28348. The error code is 0xc0000005. This error may
be a bug in the CLR or in the unsafe or non-verifiable portions of user code.
Common sources of this bug include user marshaling errors for COM-interop or
PInvoke, which may corrupt the stack".
I can't change nor the dll neither it's API.
What is the problem and what should I do to avoid it?