CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2008
    Posts
    4

    Cant make EnumWindowsProc work

    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):
    Code:
    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.
    Code:
    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:
    Code:
    #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.

  2. #2
    Join Date
    Jun 2007
    Location
    MA-USA
    Posts
    247

    Re: Cant make EnumWindowsProc work

    Try it like so...
    Code:
    EnumWindows((WNDENUMPROC)EnumWindowsProc,0);

  3. #3
    Join Date
    Dec 2008
    Posts
    4

    Re: Cant make EnumWindowsProc work

    Quote Originally Posted by bitshifter420 View Post
    Try it like so...
    Code:
    EnumWindows((WNDENUMPROC)EnumWindowsProc,0);
    Yup. Cant believe it was that easy =)
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured