473,383 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

cast to __nogc pointer from IntPtr

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
Nov 17 '05 #1
2 1319
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)...

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #2
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
"Tomas Restrepo (MVP)" <to****@mvps.org> wrote in message
news:eU**************@TK2MSFTNGP09.phx.gbl...
Dirk,

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)...

--
Tomas Restrepo
to****@mvps.org

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeff | last post by:
I am struggling with the following How do I marshal/access a pointer to an array of strings within a structure Than Jef ----------------------------------------------------------------
8
by: TJ | last post by:
I need to be able to pass a pointer to a (managed code) Stream object to a COM method so it can serialize its data into the stream. I have a C# application that makes uses of Randolf Duke's...
15
by: Edward Diener | last post by:
Why is it impossible to have a __value class instance variable in a __nogc class when it is possible to have a built-in type instance variable in a __nogc class ? __value class X { int a; };...
18
by: Edward Diener | last post by:
Is the packing alignment of __nogc classes stored as part of the assembly ? I think it must as the compiler, when referencing the assembly, could not know how the original data is packed otherwise....
1
by: Chris | last post by:
Hi, if have a __gc class with a datamember of type : a pointer to a DateTime, but I get a compiler error : __gc class Employee { public: DateTime * m_hiringDate; ==> error : cannot...
6
by: Tim | last post by:
I'm trying to co-erce a __gc array of Byte to a __nogc pointer to char to pass to a native function call in a bit of managed c++ code like this: Byte field __gc = dynamic_cast<Byte...
16
by: Dave | last post by:
I'm having a problem trying to set up code in VB to handle the case where an argument in an API definition is defined as a pointer to a pointer. An excerpt from the API's definition is: void...
5
by: SpotNet | last post by:
Hi Newsgroup, While trying to customise my common dialogs and learn C#, I'm having trouble getting this to work; OFNOTIFY ofny = (OFNOTIFY)Marshal.PtrToStructure(lParam, typeof(OFNOTIFY)); ...
4
by: Abra | last post by:
I have an application where I need to send a inter-process message (a data stream) that contains among other the address of a function (member of a class). For that, I need to serialize it, so I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.