[英]How do I call a function that is member of a class, from another function?
So I have the following: 所以我有以下几点:
INT CMainFrm::load(Cstring path)
{
}
extern "C"
{
EXPORT void fileLoad(CString filePath)
{
CMainFrm *cmf = new CMainFrm();
cmf->load(filePath);
}
}
Both are located in mainfrm.cpp. 两者都位于mainfrm.cpp中。
fileLoad()
is called from a dll and that works fine. 从dll调用
fileLoad()
,并且效果很好。 When I try to call load()
from inside fileload()
it gives me unhandled exception...I also tried calling it using an instance of CMainFrm
but the result is the same. 当我尝试从
fileload()
内部调用load()
,它给了我未处理的异常...我也尝试使用CMainFrm
的实例来调用它,但结果是相同的。 Any suggestion on how to do this properly? 关于如何正确执行此操作的任何建议?
You need to call the CMainFrm object that already exists. 您需要调用已经存在的CMainFrm对象。 (It is created at program startup.) MFC provides a global function that you can call to get a pointer to this main window: AfxGetMainWnd().
(它是在程序启动时创建的。)MFC提供了一个全局函数,您可以调用该函数来获得指向该主窗口的指针:AfxGetMainWnd()。 You may cast the returned value to CMainFrm* and use it to call load.
您可以将返回值强制转换为CMainFrm *并使用它来调用load。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.