My code has 3 parts: c#, c++/cli, c++.
in c#, I have a struct. The struct is define to pass parameters.
//c#
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Pack=1)]
public struct NDeviceDest
{
public uint IP;
public uint pos;
}
Then in c++/cli, I have a function which use the NDeviceDest
//c++/CLI
byte NDockMaster::Init(NDeviceDest pos, uint param)
{
m_pDockMaster->Init(static_cast<DeviceDest*>pos, param);
}
*m_pDockMaster* is a pointer to native type.
The member function of Init is defined in c++ as ()
//c++
struct DeviceDest
{
UINT32 IP;
unsigned int pos;
};
class DockMaster
{
public:
byte Init(DeviceDest* dest, UINT32 param)
{
return 0;
}
}
DeviceDest is defined as the exact same as NDeviceDest, to pass parameters.
Question:
In my c++/cli code, I'm using *static_cast* to make the type change. but I got compiling error:
error C2440: 'static_cast' : cannot convert from 'NDeviceDest' to 'DeviceDest *'
I'm new to c++/cli, but I think there MUST be a way to let the compiler know that NDeviceDest is DeviceDest and let me code compile and pass value from c# to cli then to c++, but I searched a lot and didn't find the exact answer.
I did find some code, but it's using pointers not structs, I also tried using pointers, but I have same error.
Thanks