C # project need to invoke the c + + dynamic link library DLL functions:
Char SetPar (char * P, long size)
P: parameter
Size: length parameter
Returns: 1 -> success, 0 - failure, busy - 1 ->
I write c # :
//define structure
[StructLayout (LayoutKind. Sequential)]
Public struct Par
{
[MarshalAs (UnmanagedType ByValArray, SizeConst=2)]
Public byte [] aa;
Public byte bb;
Public float cc.
[MarshalAs (UnmanagedType ByValArray, SizeConst=2)]
Public Int32 [] dd.
}
Referenced DLL
[DllImport (" TEST. DLL EntryPoint="SetPar CallingConvention=CallingConvention. Cdecl)]
Public extern static int SetPar (Par par1, long size);
The function
Private void btnSetPa_Click (object sender, EventArgs e)
{
Int ret=1;
Par P=new Par ();
P.a a=new byte (2);
P.a a [0]=1;
P.a a [1]=1;
P.b b=1;
P.c c=2.0;
Conviction yourself d=new byte (8);
Conviction yourself d [0]=1000;
Conviction yourself d [1]=200;
Int num=sizeof ()
Ret=SetParameter (PTR, 15);
The switch (ret)
{
Case 1:
MSG="parameter Settings success!" ;
break;
Case 0:
MSG="parameter Settings failed!" ;
break;
Case 1:
MSG="system is busy! The \ r \ n ";
break;
Default:
MSG="unknown error! The \ r \ n ";
break;
}
TxtInfo. Text=MSG;
}
According to the above method and can return 1, but there is no pass parameters in (use getPar out parameters, found no changes in parameters).
To:
Public extern static int SetPar (ref Par par1, long size);
Ret=SetParameter (ref PTR, 15);
Parameter can pass, but returned an unknown error,
How great god is this to return a responsibility excuse me? C # call c + + pointer function always don't understand ~