C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-20-2008, 07:56 AM   #1
Registered User
 
Join Date: Aug 2006
Posts: 44
Getting other processes class names

Hi again,

I am sort of stuck with detecting if a specific process is running.

My sample program is registered with class name "#32770" (a string), and for testing I know the PID.

Code:
HANDLE phandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
GetClassName(phandle, classbuf, MAX_PATH);
Using this I get different phandles everytime I call OpenProcess (yeah I do CloseHandle() them).

Here's a log:

Quote:
Error: 0. PID: 3764. classbuf: RICHEDIT. Handle: 248.
Error: 0. PID: 3764. classbuf: Static. Handle: 284.
Error: 1400. PID: 3764. classbuf: î‘|8’|ÿÿÿÿ2’|«’|ë’|. Handle: 300.
Error: 0. PID: 3764. classbuf: Button. Handle: 312.
Error: 0. PID: 3764. classbuf: Static. Handle: 292.
Error: 0. PID: 3764. classbuf: Static. Handle: 316.
Error: 0. PID: 3764. classbuf: Static. Handle: 324.
Error: 0. PID: 3764. classbuf: RICHEDIT. Handle: 296.
Error: 0. PID: 3764. classbuf: RichEdit20A. Handle: 340.
Error: 0. PID: 3764. classbuf: Static. Handle: 348.
Error: 0. PID: 3764. classbuf: RichEdit20A. Handle: 364.
Error: 0. PID: 3764. classbuf: Static. Handle: 356.
Error: 0. PID: 3764. classbuf: Button. Handle: 372.
Error: 0. PID: 3764. classbuf: Static. Handle: 376.
Error: 0. PID: 3764. classbuf: RICHEDIT. Handle: 388.
Error: 0. PID: 3764. classbuf: Afx:00400000:0. Handle: 404.
Error: 0. PID: 3764. classbuf: CiceroUIWndFrame. Handle: 396.
Error: 0. PID: 3764. classbuf: CicMarshalWndClass. Handle: 412.
Error: 0. PID: 3764. classbuf: Edit. Handle: 424.
Error: 0. PID: 3764. classbuf: Static. Handle: 380.
Error: 0. PID: 3764. classbuf: SystemTray_Main. Handle: 440.
Error: 0. PID: 3764. classbuf: Button. Handle: 444.
Error: 0. PID: 3764. classbuf: #32770. Handle: 452.
Error: 0. PID: 3764. classbuf: Static. Handle: 464.
Error: 0. PID: 3764. classbuf: Xprt Message Window. Handle: 436.
Error: 0. PID: 3764. classbuf: RichEdit20A. Handle: 308.
Error: 0. PID: 3764. classbuf: Static. Handle: 484.
Error: 0. PID: 3764. classbuf: Button. Handle: 496.
Error: 0. PID: 3764. classbuf: msctls_progress32. Handle: 460.
Error: 0. PID: 3764. classbuf: Static. Handle: 492.
Error: 0. PID: 3764. classbuf: Static. Handle: 516.
Error: 0. PID: 3764. classbuf: Static. Handle: 524.
Error: 0. PID: 3764. classbuf: Static. Handle: 532.
Error: 0. PID: 3764. classbuf: Static. Handle: 540.
Error: 0. PID: 3764. classbuf: KHALMainProcessWindow. Handle: 552.
Error: 0. PID: 3764. classbuf: KHALUSB_MainWindow. Handle: 556.
Error: 0. PID: 3764. classbuf: KHALMouseware_MainWindow. Handle: 548.
Error: 1400. PID: 3764. classbuf: î‘|8’|ÿÿÿÿ2’|«’|ë’|. Handle: 572.
Error: 0. PID: 3764. classbuf: Afx:400000:0. Handle: 584.
Error: 0. PID: 3764. classbuf: Afx:400000:0. Handle: 588.
Error: 0. PID: 3764. classbuf: Button. Handle: 596.
Error: 0. PID: 3764. classbuf: Button. Handle: 608.
Error: 0. PID: 3764. classbuf: Button. Handle: 612.
Error: 0. PID: 3764. classbuf: KHALMOU_MainWindow. Handle: 564.
Error: 0. PID: 3764. classbuf: URL Moniker Notification Window. Handle: 580.
Error: 1400. PID: 3764. classbuf: î‘|8’|ÿÿÿÿ2’|«’|ë’|. Handle: 636.
Error: 0. PID: 3764. classbuf: IME. Handle: 660.
Error: 1400. PID: 3764. classbuf: î‘|8’|ÿÿÿÿ2’|«’|ë’|. Handle: 664.
Error: 1400. PID: 3764. classbuf: î‘|8’|ÿÿÿÿ2’|«’|ë’|. Handle: 644.
Error: 0. PID: 3764. classbuf: OleMainThreadWndClass. Handle: 672.
Error: 0. PID: 3764. classbuf: Afx:400000:803:1001f:0:0. Handle: 676.
Error: 1400. PID: 3764. classbuf: î‘|8’|ÿÿÿÿ2’|«’|ë’|. Handle: 652.
Error: 0. PID: 3764. classbuf: Afx:400000:0. Handle: 692.
Error: 0. PID: 3764. classbuf: KodiakHiddenWndClass. Handle: 684.
Error: 0. PID: 3764. classbuf: #32770. Handle: 712.
Error: 0. PID: 3764. classbuf: KodiakHiddenWndClass. Handle: 700.
Error: 0. PID: 3764. classbuf: SkinWnd. Handle: 708.
Error: 0. PID: 3764. classbuf: SysListView32. Handle: 736.
Error: 0. PID: 3764. classbuf: Internet Explorer_Hidden. Handle: 724.
Error: 0. PID: 3764. classbuf: SysHeader32. Handle: 732.
Error: 0. PID: 3764. classbuf: Button. Handle: 760.
Error: 0. PID: 3764. classbuf: SysHeader32. Handle: 748.
Error: 1400. PID: 3764. classbuf: î‘|8’|ÿÿÿÿ2’|«’|ë’|. Handle: 776.
Error: 1400. PID: 3764. classbuf: î‘|8’|ÿÿÿÿ2’|«’|ë’|. Handle: 668.
Error: 0. PID: 3764. classbuf: Button. Handle: 756.
Error: 0. PID: 3764. classbuf: #32770. Handle: 800.
Error: 0. PID: 3764. classbuf: MozillaDropShadowWindowClass. Handle: 804.
Error: 0. PID: 3764. classbuf: Internet Explorer_Server. Handle: 812.
Error: 0. PID: 3764. classbuf: tooltips_class32. Handle: 788.
Error: 0. PID: 3764. classbuf: Shell Embedding. Handle: 832.
Every call to OpenProcess invokes strange behaviour IMO. phandle returns raising numbers, sometimes the function even fails (Error 1400 = "Invalid window handle.") and sometimes it returns a handle which gives me the class name I have registered.

Is this the wrong way to get the class name of other processes? If I knew the class name (which I do actually) I could check with FindWindow() if the process is running - but that would cause me problems if there are multiple instances of the process, wouldn't it?

Thanks in advance, Hawk
Hawkin is offline   Reply With Quote
Old 03-20-2008, 09:04 AM   #2
Registered User
 
Codeplug's Avatar
 
Join Date: Mar 2003
Posts: 3,844
You are mixing "handle" types. OpenProcess() returns a HANDLE to a process. GetClassName() requires a "handle" to a window of type HWND.

gg
Codeplug is offline   Reply With Quote
Old 03-20-2008, 11:22 AM   #3
Registered User
 
Join Date: Aug 2006
Posts: 44
How do I enumerate the HWNDs of a process then?
Hawkin is offline   Reply With Quote
Old 03-20-2008, 04:02 PM   #4
Registered User
 
Codeplug's Avatar
 
Join Date: Mar 2003
Posts: 3,844
You could enumerate all windows and use GetWindowThreadProcessId() to see if it belongs to a particular process.

>> am sort of stuck with detecting if a specific process is running.
>> ...and for testing I know the PID
What exactly are you trying to do?

gg
Codeplug is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting an error with OpenGL: collect2: ld returned 1 exit status Lorgon Jortle C++ Programming 6 05-08-2009 08:18 PM
Screwy Linker Error - VC2005 Tonto C++ Programming 5 06-19-2007 02:39 PM
Creating a database Shamino Game Programming 19 06-10-2007 01:09 PM
structure vs class sana C++ Programming 13 12-02-2002 07:18 AM
Abstract class problem VanJay011379 C++ Programming 9 07-31-2002 01:30 PM


All times are GMT -6. The time now is 01:00 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22