Discussion:
? Getting CWinApp* from CWnd*/HWND
(too old to reply)
Alec S.
2004-08-01 20:35:00 UTC
Permalink
Hi,

I'm working on a Spy++/WinSpy type application where the user can drag
and drop a window picker to select a window and get a bunch of information
on it. I've got the picker working and I can already display a lot of
information about the window using the CWnd* I get. However, I cannot
figure out a way to get a pointer to the CWinApp that spawned the target
window. I would like to display some application information (especially
the command line that was passed to the program that owns the selected
window). Is there some way to get the application from a CWnd* or HWND?


Thanks.

--
Alec S.
alec <@> synetech <.> cjb <.> net
Ajay Kalra
2004-08-02 02:39:51 UTC
Permalink
The question you have to answer is: What is CWinApp for an application that
is not a MFC application? It really has no meaning if you want to generalize
the concept for every app. On other hand, you probably can find out about
the command line parameters for any app using Win32 SDK.

--
Ajay Kalra [MVP - VC++]
Post by Alec S.
Hi,
I'm working on a Spy++/WinSpy type application where the user can drag
and drop a window picker to select a window and get a bunch of information
on it. I've got the picker working and I can already display a lot of
information about the window using the CWnd* I get. However, I cannot
figure out a way to get a pointer to the CWinApp that spawned the target
window. I would like to display some application information (especially
the command line that was passed to the program that owns the selected
window). Is there some way to get the application from a CWnd* or HWND?
Thanks.
--
Alec S.
Alec S.
2004-08-02 02:52:20 UTC
Permalink
You make a good point. In fact I did a little more looking around and I
can't even figure out how to get the command line from CWinApp directly :o

What API function can I use to get the command line for another app?


--
Alec S.
Post by Ajay Kalra
The question you have to answer is: What is CWinApp for an application that
is not a MFC application? It really has no meaning if you want to generalize
the concept for every app. On other hand, you probably can find out about
the command line parameters for any app using Win32 SDK.
--
Ajay Kalra [MVP - VC++]
Ajay Kalra
2004-08-02 03:09:04 UTC
Permalink
You can use GetCommandLine or for MFC apps, use CCommandLineInfo class. In
addition CWinApp::ParseCommandLine() will be useful as well.

--
Ajay Kalra [MVP - VC++]
Post by Alec S.
You make a good point. In fact I did a little more looking around and I
can't even figure out how to get the command line from CWinApp directly
:o
Post by Alec S.
What API function can I use to get the command line for another app?
--
Alec S.
Post by Ajay Kalra
The question you have to answer is: What is CWinApp for an application
that
Post by Ajay Kalra
is not a MFC application? It really has no meaning if you want to
generalize
Post by Ajay Kalra
the concept for every app. On other hand, you probably can find out about
the command line parameters for any app using Win32 SDK.
--
Ajay Kalra [MVP - VC++]
Alec S.
2004-08-02 05:07:30 UTC
Permalink
But those let me get the command line of my own app. I need a way of
getting the command line of some other (external) app.


--
Alec S.
Post by Ajay Kalra
You can use GetCommandLine or for MFC apps, use CCommandLineInfo class. In
addition CWinApp::ParseCommandLine() will be useful as well.
--
Ajay Kalra [MVP - VC++]
Post by Alec S.
You make a good point. In fact I did a little more looking around
and
Post by Ajay Kalra
I
Post by Alec S.
can't even figure out how to get the command line from CWinApp directly
:o
Post by Alec S.
What API function can I use to get the command line for another app?
--
Alec S.
Post by Ajay Kalra
The question you have to answer is: What is CWinApp for an application
that
Post by Ajay Kalra
is not a MFC application? It really has no meaning if you want to
generalize
Post by Ajay Kalra
the concept for every app. On other hand, you probably can find out
about
Post by Alec S.
Post by Ajay Kalra
the command line parameters for any app using Win32 SDK.
--
Ajay Kalra [MVP - VC++]
Gary Chang
2004-08-02 06:34:25 UTC
Permalink
Hi Alec,
I need a way of getting the command line of some other (external) app.
It appears no such API for that purpose.


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Alec S.
2004-08-02 17:21:02 UTC
Permalink
So you're saying there really is ABSOLUTELY NO WAY of getting the
command line from a different process? That sounds rather odd. Or do you
mean that there is no API and it would have to be done manually? If it can
be done manually, how? Is there a way of getting a handle to the process
owning a CWnd and then some way of getting the command line from that? Suck
it out of the PSP?


--
Alec S.
Post by Gary Chang
Hi Alec,
I need a way of getting the command line of some other (external) app.
It appears no such API for that purpose.
Thanks!
Best regards,
Gary Chang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Gary Chang
2004-08-03 02:26:40 UTC
Permalink
Hi Alec,

.. yes, there is no such API to retrieve the command-line string of
another process directly,

If you want to do that, you have to execute the GetCommandLine inside the
targeting process's space, you can use the following approach to do that,
Inject DLL or CreateRemoteThread to the targeting process, please refer to
the following article and samples:

Three Ways to Inject Your Code into Another Process
http://www.codeproject.com/threads/winspy.asp


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Alec S.
2004-08-04 21:44:17 UTC
Permalink
Hi Gary,

I read over the article you referenced and tried the solution you
attached. Unfortunately when I use the picker to select a window, the
target application (window) always crashes immediately as does the window
directly beneath it. The data displayed in WInSpy is for the second window
(the one beneath the target window) and the cmd line field is blank (even
though it shouldn't be). Does the program work on your system? Maybe it's
an OS issue? A permission issue?


--
Alec S.
Hi Alex,
Did you review Robert Kuster's article I recommended, it appears the
CreateRemoteThread would be the mothod you wanted, I have modified
Robert's
sample project WinSpy to your needs, the following is the modified remote
thread function and GetCommandLineRemote function, the attachment is the
Loading...