Click to See Complete Forum and Search --> : Cant make EnumWindowsProc work


AVRG
December 12th, 2008, 02:13 PM
Hello,

I have the following problem:
I need to get a list of all active windows. For that, I'm trying to use EnumWindows function and that means that I overwrite EnumWindowsProc.
This functions shoul look like this (taken from msdn.microsoft.com):

BOOL EnumWindows(WNDENUMPROC lpEnumFunc, LPARAM lParam);

Parameters:
lpEnumFunc
[in] Pointer to an application-defined callback function. For more information, see EnumWindowsProc.
lParam
[in] Specifies an application-defined value to be passed to the callback function.

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);

Parameters:
hwnd
[in] Handle to a top-level window.
lParam
[in] Specifies the application-defined value given in EnumWindows or EnumDesktopWindows.

I wrote a small test .dll:

#include <windows.h>
#include <vcl.h>

BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) {
return TRUE;
}

int APIENTRY DllMain (HINSTANCE hInstance,
DWORD ulReason,
LPVOID lpReserved)
{
EnumWindows(EnumWindowsProc, NULL);
return 1;
}
But whenever i try to compile it, i get the following message:
[C++ Error] Unit1.cpp(60): E2342 Type mismatch in parameter 'lpEnumFunc' (wanted 'int (__stdcall *)()', got 'int (__stdcall *)(void *,long)')

If I remove parameters from EnumWindowsProc it will work, but then I dont know why would I need it to =)
I'd be really grateful for any idea why is that happening.

Thanks.

bitshifter420
December 12th, 2008, 08:20 PM
Try it like so...EnumWindows((WNDENUMPROC)EnumWindowsProc,0);

AVRG
December 13th, 2008, 02:41 AM
Try it like so...EnumWindows((WNDENUMPROC)EnumWindowsProc,0);

Yup. Cant believe it was that easy =)
Thanks.