DLL中函数返回CString的问题

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

    我用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 _CrtIsValidHeapPointer are removed during pre

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值