C
Carsten Unterberg
Hi everyone,
i've got a problem with interop.
in this case, i've a c++-application for a mobile device which sends my
other application (.net cf) via SendNotifyMessage a wm_copydata message
with a own structure.
structure in c++
struct sData
{
public:
int id;
char szData[500];
public:
sData()
{
memset(this, NULL, sizeof(sData));
}
public:
void SetData(int iApp, char* pszData)
{
strcpy(szData, pszData);
id = sizeof(szData);
}
};
structure in c#
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential,CharSet
= System.Runtime.InteropServices.CharSet.Unicode)]
public struct sData
{
public System.Int32 id;
[System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=500)]
public sbyte[] szData;
}
sending and receiving works without any problems. but when i try to parse
the incoming data with that:
COPYDATASTRUCT cdata =
(COPYDATASTRUCT)System.Runtime.InteropServices.Marshal.PtrToStructure(e.Message.LParam,
typeof(COPYDATASTRUCT));
sData data =
(sData)System.Runtime.InteropServices.Marshal.PtrToStructure(cdata.lpData,
typeof(sData));
has data.szData not the value which i give him in the c++-application.
maybe there is an error, but i don't know where.
Best Regards,
Carsten Unterberg | Test-Framework
http://test-framework.blogspot.com/
i've got a problem with interop.
in this case, i've a c++-application for a mobile device which sends my
other application (.net cf) via SendNotifyMessage a wm_copydata message
with a own structure.
structure in c++
struct sData
{
public:
int id;
char szData[500];
public:
sData()
{
memset(this, NULL, sizeof(sData));
}
public:
void SetData(int iApp, char* pszData)
{
strcpy(szData, pszData);
id = sizeof(szData);
}
};
structure in c#
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential,CharSet
= System.Runtime.InteropServices.CharSet.Unicode)]
public struct sData
{
public System.Int32 id;
[System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=500)]
public sbyte[] szData;
}
sending and receiving works without any problems. but when i try to parse
the incoming data with that:
COPYDATASTRUCT cdata =
(COPYDATASTRUCT)System.Runtime.InteropServices.Marshal.PtrToStructure(e.Message.LParam,
typeof(COPYDATASTRUCT));
sData data =
(sData)System.Runtime.InteropServices.Marshal.PtrToStructure(cdata.lpData,
typeof(sData));
has data.szData not the value which i give him in the c++-application.
maybe there is an error, but i don't know where.
Best Regards,
Carsten Unterberg | Test-Framework
http://test-framework.blogspot.com/