EnumWindow() and More

I'm trying to learn to use EnumWindows() and a whole chain of others to check if one of the open windows is of a certain program. I've built a test set up. Here is my EnumWindowsProc():

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
	DWORD procid;
	GetWindowThreadProcessId(hwnd, &procid);
	HANDLE hProcess = OpenProcess(READ_CONTROL, FALSE, procid);

	HMODULE hMod;
	DWORD cbNeeded;
	EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded);

	TCHAR szProcessName[MAX_PATH] = TEXT("Unknown");
	GetModuleBaseName(hProcess, hMod, szProcessName, procid);

	MessageBox(NULL, szProcessName, TEXT("Process Name"),
		MB_OK);

	CloseHandle(hProcess);
	return TRUE;
}


Note: It returns true because I have no idea what I'm supposed to return at this point. I'm relatively new to windows programming.

I have a Win32 window built, and in the middle of that code I have a call to EnumWindows that looks like EnumWindows(EnumWindowsProc, 0);. I don't quite know if that's how I'm supposed to be doing it yet, but I'll figure that out eventually. I'm more concerned with getting the thing to build first.

Anyway, I'm using VS 2008 Express, and when I try to build I get a couple linker errors:

1
2
3
4
5
6
7
1
1>Linking...
1>test.obj : error LNK2019: unresolved external symbol _GetModuleBaseNameW@16 referenced in function "int __stdcall EnumWindowsProc(struct HWND__ *,long)" (?EnumWindowsProc@@YGHPAUHWND__@@J@Z)
1>test.obj : error LNK2019: unresolved external symbol _EnumProcessModules@16 referenced in function "int __stdcall EnumWindowsProc(struct HWND__ *,long)" (?EnumWindowsProc@@YGHPAUHWND__@@J@Z)
1>G:\Documents and Settings\Cyle\My Documents\Visual Studio 2008\Projects\Win32_Tutorial2\Debug\Win32_Tutorial2.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://g:\Documents and Settings\Cyle\My Documents\Visual Studio 2008\Projects\Win32_Tutorial2\Win32_Tutorial2\Debug\BuildLog.htm"
1>Win32_Tutorial2 - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


That's the entire output. Anyway, I just recently figured out how to even use the linker, but I'm not sure what the problem is. Does anyone know what I need to do to get this to build?

Also, if I'm doing something wrong in the code itself, don't hesitate to let me know. I pretty much just looked up the functions on MSDN and tried to write some code to get something working, then just fixed compiler error one at a time.

Anyway, any help is much appreciated.
MSDN says that for the
GetModuleBaseName and EnumProcessModule functions:

You need to include include Psapi.h and link against
Psapi.lib.
Oh, I overlooked that >_<

Thank you.
Also, just return false if the base name matches. This way you can break from your callback function & if EnumWindows return TRUE it means the window wasn't found.
Topic archived. No new replies allowed.