Skip to content

The dismatching error with "unsafe"

rsm1235

Asked Feb 10, 2006, 5:59 AM EST2 answers
Share
LinkedInX

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:

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?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Anwar Buchoo
    0

    Try to compile your code using the csc (C-Sharp Compiler) from the Visual Studio .NET Command Prompt and specify the switch /unsafe


    Rgds.

    0
  • 1 short reply
    • 0

      sorry,dismatch mean mismatch

      0