user3742860
user3742860

Reputation: 100

findwindow doesn't work c++

So Im trying to create a camo unlocker but I have never had trouble with getting process id through findwindow

but now Im trying to find black ops 2's proc id but the window name doesn't work

Call of Duty®: Black Ops II

CODE:

#include <iostream>
#include <Windows.h>
#include <tchar.h>

using namespace std;

int main(){

    HWND hWnd = FindWindow(0, _T("Call of Duty®: Black Ops II - Multiplayer"));

    if(hWnd){
        cout << "window found" << endl;
    }

    return 0;
}

Upvotes: 0

Views: 6644

Answers (4)

ed_me
ed_me

Reputation: 3508

It looks like the registered symbol could be unicode, you'll want to use FindWindowW():

Unicode and ANSI names
FindWindowW (Unicode) and FindWindowA (ANSI)

Alternatively, you could use FindWindowEx() and search for the window class name.

Upvotes: 4

user3742860
user3742860

Reputation: 100

FindWindowA worked for me :) so I just changed from tchar to the normal HWND hWnd = FindWindowA(0, ("Call of Duty®: Black Ops II - Multiplayer"));

Upvotes: -2

vlad_tepesch
vlad_tepesch

Reputation: 6891

I would try to find the window by class as an application may change its title and class names usually do not have fancy characters. If you do not know them look for some tool (Spy++ + i think it comes with Visual Studio) or create a list with a simple tool using EnumWindows and GetClassName

Upvotes: 1

David Heffernan
David Heffernan

Reputation: 612794

FindWindow works correctly. The possible causes for your problem are:

  1. You have an encoding error. You should use the Unicode API:

    HWND hWnd = FindWindowW(NULL, L"Call of Duty®: Black Ops II - Multiplayer");
    
  2. There is no top level window with that window text. Use a tool like Spy++ to check that.

You should also make sure that you read the documentation carefully. Specifically it states the following:

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

You should do as it says and call GetLastError in event of failure.

Upvotes: 2

Related Questions