将指向proc的指针作为参数传递

时间:2010-05-16 12:25:22

标签: c++

我想将指针传递给c ++中的过程。我尝试传递这个LRESULT(*)(HWND,UINT,WPARAM,LPARAM)prc,但它不起作用。这是怎么做到的?

由于

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

    }

}

“它没有用”我的意思是这是一个语法错误。

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

3 个答案:

答案 0 :(得分:0)

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

您也可以使用WNDPROC类型:

HWND OGLFRAME::create(HWND parent, WNDPROC prc)

答案 1 :(得分:0)

试试这个:

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

}

答案 2 :(得分:0)

声明一个接受函数指针的函数:

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

传递函数指针:

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

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