cast to __nogc pointer from IntPtr

D

Dirk

Hello

I override the WndProc method of a control-derived class and want to handle
the WM_NOTIFY message. The following code leads to a NMHDR pointer that
points to something where all members are shown as undefined in the
debugger.

NMHDR __nogc *pnmh = static_cast<NMHDR __nogc*>(msg->LParam.ToPointer());

if I redefine NMHDR as a __gc struct and do the following everything works

gc_NMHDR __gc *pnmh = __try_cast<gc_NMHDR
__gc*>(Marshal::ptrToStructure(msg->LParam, __typeof(gc_NMHDR)));

now pnmh points to struct with valid members. PtrToStructure's purpose is it
to get the data from the unmanaged heap to the managed heap. Why does the
first method fail then?
I'd like to avoid redefining the native structs and want to use the first
method.

Thanks
 
T

Tomas Restrepo \(MVP\)

Dirk,
I override the WndProc method of a control-derived class and want to handle
the WM_NOTIFY message. The following code leads to a NMHDR pointer that
points to something where all members are shown as undefined in the
debugger.

NMHDR __nogc *pnmh = static_cast<NMHDR __nogc*>(msg->LParam.ToPointer());

if I redefine NMHDR as a __gc struct and do the following everything works

gc_NMHDR __gc *pnmh = __try_cast<gc_NMHDR
__gc*>(Marshal::ptrToStructure(msg->LParam, __typeof(gc_NMHDR)));

now pnmh points to struct with valid members. PtrToStructure's purpose is it
to get the data from the unmanaged heap to the managed heap. Why does the
first method fail then?

Is it *actually* failing? So far, all you've said is the debugger can't
display it, but have you actually checked you can't access its values?

I ask this because there are some well-known issues with the debugger with
mixed-mode debugging (heck, even the managed mode debugger gets stuck
sometimes)...
 
D

dirk

Hello

No, it does not fail. Although shown as undefined comparison and
modification work. I had some other issues during my first tries that
prevented the WM_NOTIFY I was interested in from being sent. Some WM_NOTIFY
messages were sent, but because I could not easily check which one I changed
different things. So I am glad that I can use the native structs.

Thanks
 

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