Archived

This topic is now archived and is closed to further replies.

general pointer question

This topic is 5670 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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 */
/*=========================================*/

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sure (in theory, i.e. using a language construct):

CWnd *hd = reinterpret_cast<CWnd *>(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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
No, you have to post the message to the window. Try to ::SetFocus() to that window, prior posting the message. Alternatively, try using the ::SendInput() or ::mouse_event() functions.

Forever trusting who we are
And nothing else matters
- Metallica

Share this post


Link to post
Share on other sites