Execute C++ function from C# crashes
I need to call a function from a C++ dll file, in C#.
From the C++ Header file, I know:
typedef struct {
bool CashIn;
bool Surplus;
bool Fitness;
char Denomination[N_DIV][MAX_CURR_NAME];
byte DenominationNumber;
byte RollNumber;
bool CanbeChanged;
}NT_Roll;
extern "C" int WINAPI Cima_NT_GetRollsConfiguration(NT_Roll
*Configuration,int *CfgSize);
I used the following in C# application
[DllImport("Cima_NT_Drv")]
unsafe static extern int Cima_NT_GetRollsConfiguration( out NTRoll[]
ntRoll, ref int CfgSize);
[StructLayout(LayoutKind.Sequential)]
unsafe struct NTRoll
{
public byte CashIn;
public byte Surplus;
public byte Fitness;
public fixed byte Denomination[N_DIV * MAX_CURR_NAME];
public byte DenominationNumber;
public byte RollNumber;
public byte CanbeChanged;
}
And the function call is:
public unsafe int GetRollsConfiguration(out RollerConfig[] OutRolls)
{
NTRoll[] Rolls = null;
int configSize = 16;
int result = -1;
result = Cima_NT_GetRollsConfiguration(out Rolls, ref configSize);
return result;
}
I don't have the code of the C++ DLL. The execution of
Cima_NT_GetRollsConfiguration(out Rolls, ref configSize); makes the
application crashes without any error message.
Is there anything wrong with the C# code?
No comments:
Post a Comment