function pointer ,,,easy but not simple
-
I have a problem with using function poiter. My program has two parts: part 1: mydll.dll typedef BOOL (*SpeakFunc)(const CString s); #define DLL_EXPORT __declspec(dllexport) BOOL DLL_EXPORT Init(HWND hwnd,SpeakFunc func) { ... } part 2: adding the mydll.lib of the part 1 into the project of the part 2 in the test.cpp file of the "Test" class typedef BOOL (*SpeakFunc)(const CString str); extern BOOL Init(HWND hwnd,SpeakFunc func); BOOL CTest::Speak(const CString) { ... } void CTest::TestMethod() { ... Init (NULL,&CTest::Speak) ; // the compiler notices an error here ... } The error message like below: "error C2440: 'initializing' : cannot convert from 'int (__thiscall CTest::*)(const class CString)' to 'int (__cdecl *)(const class CString)' There is no context in which this conversion is possible" please help me...Thanks a lot.
-
I have a problem with using function poiter. My program has two parts: part 1: mydll.dll typedef BOOL (*SpeakFunc)(const CString s); #define DLL_EXPORT __declspec(dllexport) BOOL DLL_EXPORT Init(HWND hwnd,SpeakFunc func) { ... } part 2: adding the mydll.lib of the part 1 into the project of the part 2 in the test.cpp file of the "Test" class typedef BOOL (*SpeakFunc)(const CString str); extern BOOL Init(HWND hwnd,SpeakFunc func); BOOL CTest::Speak(const CString) { ... } void CTest::TestMethod() { ... Init (NULL,&CTest::Speak) ; // the compiler notices an error here ... } The error message like below: "error C2440: 'initializing' : cannot convert from 'int (__thiscall CTest::*)(const class CString)' to 'int (__cdecl *)(const class CString)' There is no context in which this conversion is possible" please help me...Thanks a lot.
In "part 1" you declare
SpeakFunc
as a global function but in "part 2" you attempt to pass a pointer to a member function. Steve -
I have a problem with using function poiter. My program has two parts: part 1: mydll.dll typedef BOOL (*SpeakFunc)(const CString s); #define DLL_EXPORT __declspec(dllexport) BOOL DLL_EXPORT Init(HWND hwnd,SpeakFunc func) { ... } part 2: adding the mydll.lib of the part 1 into the project of the part 2 in the test.cpp file of the "Test" class typedef BOOL (*SpeakFunc)(const CString str); extern BOOL Init(HWND hwnd,SpeakFunc func); BOOL CTest::Speak(const CString) { ... } void CTest::TestMethod() { ... Init (NULL,&CTest::Speak) ; // the compiler notices an error here ... } The error message like below: "error C2440: 'initializing' : cannot convert from 'int (__thiscall CTest::*)(const class CString)' to 'int (__cdecl *)(const class CString)' There is no context in which this conversion is possible" please help me...Thanks a lot.
See the FAQ 6.5 How do I declare and use a pointer to a class member function?[^] --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ