Getting other processes class names

This is a discussion on Getting other processes class names within the Windows Programming forums, part of the Platform Specific Boards category; Hi again, I am sort of stuck with detecting if a specific process is running. My sample program is registered ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    68

    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:

    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

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,643
    You are mixing "handle" types. OpenProcess() returns a HANDLE to a process. GetClassName() requires a "handle" to a window of type HWND.

    gg

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    68
    How do I enumerate the HWNDs of a process then?

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,643
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

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

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