我用MFC做了个Regular DLL,其中一个接口形如:
CString GetName(...);
或者:
void GetName(CString &);
应用程序一般这样来调用: CString name = GetName(...);或者GetName(name)
我自己用得好好的,别人使用该DLL的时候居然出现_CrtIsValidHeapPointer的异常,原因在msdn中说得很清楚:
The _CrtIsValidHeapPointer function is used to ensure that a specific memory address is within the local heap. The “local” heap refers to the heap created and managed by a particular instance of the C run-time library. If a dynamically linked library (DLL) contains a static link to the run-time library, then it has its own instance of the run-time heap, and therefore its own heap, independent of the application’s local heap. When _DEBUG is not defined, calls to

当一个MFC Regular DLL中的函数返回或接受CString类型参数时,如果DLL和应用程序的MFC运行时库链接方式不一致,可能会导致_CrtIsValidHeapPointer异常。这是因为DLL和应用程序可能拥有独立的内存堆。解决方法包括确保DLL和应用程序的编译模式(Debug/Release)、运行时库链接方式(Static/Shared Multi-Threaded DLL)相同。尽管如此,调试版本下只有特定配置才能正常工作,且CWnd::GetWindowText(CString &)函数未遇到此问题。
最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



