Hi,
I have such simple structure in unmanaged C++:
struct Cam
{
char ip[16];
char login[16];
char pass[16];
char name[16];
};
and C# marshalled structure:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
public struct Cam
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string ip;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string login;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string pass;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string name;
}
When I pass C# struct to C++ lib by function
[DllImport("NVRLib.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void AddCameraStruct(Cam cam);
...
Cam cam = new Cam();
cam.ip = "192.168.0.232";
cam.login = "admin";
cam.pass = "admin";
cam.name = "kekekeke";
AddCameraStruct(cam);
and print passed values in C++:
__declspec(dllexport) void AddCameraStruct(Camera cam)
{
printf(cam.ip);
printf("\n");
printf(cam.login);
printf("\n");
printf(cam.name);
printf("\n");
printf(cam.pass);
strcpy(camera[CAM_NUM].ip, cam.ip);
strcpy(camera[CAM_NUM].login, cam.login);
strcpy(camera[CAM_NUM].pass, cam.pass);
strcpy(camera[CAM_NUM].name, cam.name);
CAM_NUM++;
}
it prints:
232
<EMPTY LINE>
192.168.0.232
n
What am I doing wrong?