B
BMermuys
Hi,
inline
Not inside a struct.
Change the last field into :
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=21)]
public string card_number;
HTH,
greetings
inline
roben said:Hi,
I need to call a function in a c++ dll with a struct.
It works fine with the integeres - but the char[] variable doesnt.
I also tried using StringBuilder
Not inside a struct.
as I have seen suggested around the net,
but it just crashes my program.
Can anyone help ?
-----------------
C# code
-----------------
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct RBN
{
public int card_expirymonth;
public int card_expiryyear;
public char[] card_number;
Change the last field into :
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=21)]
public string card_number;
HTH,
greetings
}
[DllImport("myext.dll")] public static extern int Rbnfunc(ref RBN a);
RBN b = new RBN();
b.card_expirymonth = 4;
b.card_expiryyear = 7;
b.card_number = "12345678".ToCharArray();
AuthResult = Rbnfunc(ref b);
-----------------
C++ code
-----------------
struct RBN
{
int rbn_expirymonth;
int rbn_expiryyear;
char card_number[21];
}