Advertisement

general pointer question

Started by June 05, 2002 02:31 AM
10 comments, last by nextgengamer 22 years, 6 months ago
Hi, I was wondering if there was any way to hard code the memory address that a pointer points to? I''m looking for something like this: CWnd *hd = 0x000000fc; Thanks NextGenGamer
DANGER! DANGER! WILL ROBINSON!

But seriously, I don''t think you can. Even if you can, it''s extrememly dangerous. Why do you want to?

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
Advertisement
Yes, that works. You may need to put a cast in there though. If it needs to have a constructor called for that location, use placement new. There are few situations (or none, for most projects) where you''d need to do something like that though.

Sure (in theory, i.e. using a language construct):
CWnd *hd = reinterpret_cast&#60CWnd *>(0x000000fc);  

But that does not make sense. At the address 0x000000fc there will be no valid CWnd, not to speak about the fact that 0x000000fc might not even be a valid address. You'll get a crash as soon as you try to use "hd".

What exactly do you want to do?

[edit] darn tags!
Forever trusting who we are
And nothing else matters
- Metallica


[edited by - Gabriel Fleseriu on June 5, 2002 3:41:08 AM]
Forever trusting who we areAnd nothing else matters - Metallica
Thanks for the quick reply

I figured it out while waiting though.

CWnd *hd = (CWnd *) 0x000000CD;

The typecast was all i needed.
You are right Gabriel there is no CWnd there I am trying to get at a window inside a window that is not part of my program. I am experimenting using "My Computer" and the "FolderView" that takes the WM_LBUTTONDBLCLK message to go into folders. I did get a crash as soon as I ran because of there not being a CWnd. Do you know of anyway I can get access at "FolderView" inside my computer? I am using Spy++ to track the messages and handles?

Advertisement
quote: Original post by nextgengamer
Thanks for the quick reply

I figured it out while waiting though.

CWnd *hd = (CWnd *) 0x000000CD;

The typecast was all i needed.


Aside: prefere using C++ casts instead of C style casts. A C style cast will apply any combination of C++ casts to get the job done, so you actually have less controle when using them.



Forever trusting who we are
And nothing else matters
- Metallica
Forever trusting who we areAnd nothing else matters - Metallica
quote: Original post by nextgengamer
You are right Gabriel there is no CWnd there I am trying to get at a window inside a window that is not part of my program. I am experimenting using "My Computer" and the "FolderView" that takes the WM_LBUTTONDBLCLK message to go into folders. I did get a crash as soon as I ran because of there not being a CWnd. Do you know of anyway I can get access at "FolderView" inside my computer? I am using Spy++ to track the messages and handles?



Use EnumChildWindows() if you have the handle of the "main" window. Actually you could use EnumWindows() to get the desired window handle, then EnumChildWindows() to pick the child, and do something with it.

I don't know what you are aiming at, so I cannot give more specific advice. Could you elaborate a little bit, please?

[edit]: You should not confuze a window handle with a pointer.

Forever trusting who we are
And nothing else matters
- Metallica


[edited by - Gabriel Fleseriu on June 5, 2002 3:51:51 AM]
Forever trusting who we areAnd nothing else matters - Metallica
Gabriel, for tonight I would just be happy with getting my program to dbl click on an icon in the "My Computer" window and open that folder as if I just clicked it on my own. With Spy++ I have realized that the correct window is recieving the messages using CWnd::SendMessage however I think since the window is not active its not reciving this message as if it was done on the "My computer" window.
the only difference between my programs message and the actual click message (according to Spy++) is this

When you actually click on the folder:

Message : 0203 (Posted)
WM_LBUTTONDBLCLK

When my program runs :

Message : 0203 (Returned)
WM_LBUTTONDBLCLK

Any idea on how to get "My Computer" to post my message?

This topic is closed to new replies.

Advertisement