Struct MyStruct
{
Int Width;
Int Height;
};
Extern "C" _declspec (dllexport) int the Add (MyStruct MyStruct)
{
Return myStruct. Width + myStruct. Height;
}
CSharp code and then the upper machine
[StructLayout (LayoutKind. Sequential)]
Public struct MyStruct
{
Public int Width {get; The set; }
Public int Height {get; The set; }
}
[DllImport (" OpenCvHelper. DLL)]
Public static extern int the Add ([MarshalAs (UnmanagedType. Struct)] MyStruct MyStruct);
Because data structure needs to be quoted PC wanted to use classes to encapsulate data, so how to do? The also want to use such a machine? Or is there any way to change my?
Only this score, I hope experienced gives directions thank you.
CodePudding user response:
Mentioned as if Microsoft can only use structure, cannot use classes,In seen post friend leave a message, send points!
CodePudding user response:
Preach the difference between class and struct is the difference between 'reference' and 'values',To class in the c #, c + + to receive references,
Extern "C" _declspec (dllexport) int the Add (const MyStruct & amp;
myStruct){
Return myStruct. Width + myStruct. Height;
}