How to show text in a form edit box that is being send to a static function from DLL? [duplicate]

柔情痞子 提交于 2021-02-11 12:50:33

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!