the dismatching error with "unsafe"

S

shengmin.ruan

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?
 
W

Willy Denoyette [MVP]

What do you mean with a "dismatching error"?

Willy.

|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?
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top