tags:

views:

43

answers:

3

I want to pass a pointer to a procedure in c++. I tried passing this LRESULT(*)(HWND, UINT, WPARAM, LPARAM) prc but it didn't work. How is this done?

Thanks

HWND OGLFRAME::create(HWND parent, LRESULT(*)(HWND, UINT, WPARAM, LPARAM) prc)
{
    if(framehWnd != NULL)
    {
        return framehWnd;
        ZeroMemory(&rwc,sizeof(rwc));

    }

}

By "it didn't work" I mean it's a syntax error.

from the compiler:
Error   2   error C3646: 'prc' : unknown override specifier c:\users\josh\documents\visual studio 2008\projects\vectorizer project\vectorizer project\oglframe.h    10
Error   5   error C3646: 'prc' : unknown override specifier c:\users\josh\documents\visual studio 2008\projects\vectorizer project\vectorizer project\oglframe.cpp  7
Error   1   error C2146: syntax error : missing ')' before identifier 'prc' c:\users\josh\documents\visual studio 2008\projects\vectorizer project\vectorizer project\oglframe.h    10
Error   4   error C2146: syntax error : missing ')' before identifier 'prc' c:\users\josh\documents\visual studio 2008\projects\vectorizer project\vectorizer project\oglframe.cpp  7
Error   3   error C2059: syntax error : ')' c:\users\josh\documents\visual studio 2008\projects\vectorizer project\vectorizer project\oglframe.h    10
Error   6   error C2059: syntax error : ')' c:\users\josh\documents\visual studio 2008\projects\vectorizer project\vectorizer project\oglframe.cpp  7
A: 
HWND OGLFRAME::create(HWND parent, LRESULT(*prc)(HWND, UINT, WPARAM, LPARAM))

You could also just use the WNDPROC type:

HWND OGLFRAME::create(HWND parent, WNDPROC prc)
Marcelo Cantos
Don't forget that the first version needs to use the `CALLBACK` calling convention.
In silico
A: 

Try this:

HWND OGLFRAME::create(HWND parent, LRESULT(*wndproc)(HWND, UINT, WPARAM, LPARAM))
{

}
zdawg
Don't forget that window procedures use the `CALLBACK` calling convention.
In silico
A: 

To declare a function that accepts a function pointer:

// Note the CALLBACK calling convention!
HWND OGLFRAME::create(HWND parent,
    LRESULT (CALLBACK *prc)(HWND, UINT, WPARAM, LPARAM))
{
    // ...
}

To pass a function pointer:

// Note the CALLBACK calling convention!
LRESULT CALLBACK MyProc(HWND, UINT, WPARAM, LPARAM)
{
    // ...
}

// Note the ampersand!
oglframeinstance.create(hwnd, &MyProc);
In silico