cast to __nogc pointer from IntPtr

  • Thread starter Thread starter Dirk
  • Start date Start date
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
 
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)...
 
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
 
Back
Top