Question

I Have a app that needs detect insertion new devices. But i get a error on "wndClass.lpfnWndProc = reinterpret_cast(WndProcTest );" the error is "Member function must be called or its address taken". I use Borland C++ builder 6. Maybe someone knows what I'm doing wrong?

My code AppMainForm.cpp:

bool TAppMainForm::InitWindowClass()
{
    WNDCLASSEX wndClass;

    wndClass.cbSize = sizeof(WNDCLASSEX);
    wndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
    wndClass.hInstance = reinterpret_cast<HINSTANCE>(GetModuleHandle(0));
    wndClass.lpfnWndProc = reinterpret_cast<WNDPROC>(WndProcTest );
    wndClass.cbClsExtra = 0;
    wndClass.cbWndExtra = 0;
    wndClass.hIcon = LoadIcon(0,IDI_APPLICATION);
    wndClass.hbrBackground = CreateSolidBrush(RGB(192,192,192));
    wndClass.hCursor = LoadCursor(0, IDC_ARROW);
    wndClass.lpszClassName = g_szClassName;
    wndClass.lpszMenuName = NULL;
    wndClass.hIconSm = wndClass.hIcon;

    if ( ! RegisterClassEx(&wndClass) )
    {
        //ErrorHandler(TEXT("RegisterClassEx"));
        return false;
    }
    return true;
}

INT_PTR WINAPI TAppMainForm::WndProcTest(
        HWND hWnd,
        UINT message,
        WPARAM wParam,
        LPARAM lParam
    )
{
    // do something
}

Header File:

public: 
    bool InitWindowClass();
    INT_PTR WINAPI WndProcTest(
        HWND hWnd,
        UINT message,
        WPARAM wParam,
        LPARAM lParam
    );
Was it helpful?

Solution

The problem you've got is that you're trying to take the address of a C++ member function and assign it to a pointer to a C function, lpfnWndProc.

OTHER TIPS

Possible ways to fix this:

  1. Make the member function static

  2. Don't use a member function

  3. Declare the function static

    static INT_PTR WINAPI WndProcTest(....) { // do something }

    wndClass.lpfnWndProc = reinterpret_cast(InitWindowClass::WndProcTest );

  4. Make WndProcTest an old fashioned C function (and remove it from your class):

    INT_PTR WINAPI WndProcTest(....) { // do something }

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top