2
Reply

the dismatching error with "unsafe"

rsm1235

rsm1235

Feb 10 2006 10:59 AM
2.2k

i need to use the native code(unmanaged code),and i have to use void*,so i use the "unsafe" symbol then i meet the trouble

c++code:

SC_InitAsk sca; 
memset(&sca, 0, sizeof(sca));
sca.m_Head.m_nType = SC_INIT;
sca.m_dwSoftware = 0x12345678;
sca.m_hWnd = m_hWnd;

m_Dll.SCInit(&sca, sizeof(sca)


c# code:

unsafe
{
SC_InitAsk sca = new SC_InitAsk();
sca.m_Head.m_lIndex = PublicValue.SC_INIT;
sca.m_dwSoftware = 0x12345678;
sca.m_hWnd = this.Handle;

SCInit(&sca, sizeof(SC_InitAsk));
}

c++ interface:
BOOL WINAPI SCInit(void *pInit, int nSize);

c# reference definition:
public unsafe static extern bool SCInit(void* pInit, int nSize);

---------
my trouble:
when debug c#,i got dismatching error with the c++ interface,then i can't find out what's wrong,for the reason may be the struct definition or the "void *"

so how i can work it out ,or how i can debug this?


Answers (2)