structure mapping for wm_copy_data
-
Hi, i've two mobile application, one in c++ and the other in c# that exchange a structure with wm_copy_data. If i have a simple int inside the struct, everything work fine, but i have problem with the correct struct definition in c# code. Here is the c++ app code:
typedef struct tagMYRECASR
{
char roName[100];
char roRole[100];
char rpName[100];} MYASR;
COPYDATASTRUCT MyCDS;
MYASR MyRec;char *roName;
char *roRole;
char *rpName;CString rp = _T("rp_it-it");
CString vbRoName = rp;
vbRoName += "/";
vbRoName += grmName;CString vbRoRole = _T("");
CString vbRpName = _T("");ConvertToMultibyte(&roName,vbRoName);
ConvertToMultibyte(&roRole,vbRoRole);
ConvertToMultibyte(&rpName,vbRpName);strcpy(MyRec.roName,(const char*)roName);
strcpy(MyRec.roRole,(const char*)roRole);
strcpy(MyRec.rpName,(const char*)rpName);MyCDS.dwData = 1; // function identifier
MyCDS.cbData = sizeof( MyRec ); // size of data
MyCDS.lpData = &MyRec;
HWND window = ::FindWindow(NULL, _T("ManageWindow"));if(window!=NULL) {
::SendMessage(window, WM_COPYDATA, (WPARAM)(HWND) window, (LPARAM) (LPVOID) &MyCDS );In c# i tried to define the structure in this way:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct UserData
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public string roName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public string roRole;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public string rpName;
}and in many other way, but it doesn't work any idea? consider me a newbye. thanks in advance
-
Hi, i've two mobile application, one in c++ and the other in c# that exchange a structure with wm_copy_data. If i have a simple int inside the struct, everything work fine, but i have problem with the correct struct definition in c# code. Here is the c++ app code:
typedef struct tagMYRECASR
{
char roName[100];
char roRole[100];
char rpName[100];} MYASR;
COPYDATASTRUCT MyCDS;
MYASR MyRec;char *roName;
char *roRole;
char *rpName;CString rp = _T("rp_it-it");
CString vbRoName = rp;
vbRoName += "/";
vbRoName += grmName;CString vbRoRole = _T("");
CString vbRpName = _T("");ConvertToMultibyte(&roName,vbRoName);
ConvertToMultibyte(&roRole,vbRoRole);
ConvertToMultibyte(&rpName,vbRpName);strcpy(MyRec.roName,(const char*)roName);
strcpy(MyRec.roRole,(const char*)roRole);
strcpy(MyRec.rpName,(const char*)rpName);MyCDS.dwData = 1; // function identifier
MyCDS.cbData = sizeof( MyRec ); // size of data
MyCDS.lpData = &MyRec;
HWND window = ::FindWindow(NULL, _T("ManageWindow"));if(window!=NULL) {
::SendMessage(window, WM_COPYDATA, (WPARAM)(HWND) window, (LPARAM) (LPVOID) &MyCDS );In c# i tried to define the structure in this way:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct UserData
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public string roName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public string roRole;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public string rpName;
}and in many other way, but it doesn't work any idea? consider me a newbye. thanks in advance
Try to use StringBuilder to convert from character arrays.