问题
I am new learner and developing an MFC application and MFC shared DLL. Main application has a static function that is being called by dll as a callback and it returns a text string. I need to show this text in a edit box in form view. Please advise how to do it.
PlotterDoc.h
class PlotterDoc : public CDocument
{
public:
// A static function that is being called from DLL
static void __declspec(dllexport) callMeFromDll(string str) {
CString cstr(str.c_str());
// This cstr need to be shown in a edit box.
AfxMessageBox(cstr);
}
void (*callMeFromDllPtr)(string);
}
回答1:
This has nothing to do with DLLs. You would get the same problem without any DLL.
The problem is as the error message says, a member function pointer (what you are supplying) is not compatible with a regular function pointer (what the DLL wants). Member functions and regular functions are not the same thing (because a member function has an implicit this
parameter) and so pointers to member functions and pointers to regular functions are not compatible.
Looking at your code, there is no obvious reason why callMeFromDLL
is a member of document
. Maybe you should just move it out of that class. Making it a static member function would also work.
来源:https://stackoverflow.com/questions/66045199/how-to-show-text-in-a-form-edit-box-that-is-being-send-to-a-static-function-from