关于CrtIsValidHeapPointer的一段问答

Debug Assertion Failed!
Program: d:\dd\err.exe
File:dbgheap.c
Line:1132
Expression: _CrtIsValidHeapPointer(pUserData)

err是我的程序.

程序是调用一个DLL, 在DLL的接口只添加一个参数char* op, 好奇怪的问题.

请各位在侠指点!


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 preprocessing.

如上文所述(MSDN):
_CrtIsValidHeapPointer确认内存地址在本地堆。……如果静态链接C运行库,那么,dll拥有一个独立于应用程序(调用它的exe)的本地堆。(所以你上面的程序会Debug Assertion Failed),如果没有定义_DEBUG,那么_CrtIsValidHeapPointer将被预处理器移除。

所以方法有二:
1、动态链接C运行库。
2、设置为release版本。


多谢各位!

to sinall:
我已经全部设为release版本, 直接执行程序, 但是程序提示:遇到问题需要关闭。我们对此引起的不便表示抱歉。

是不是可能是我修改的DLL程序有问题!


嗯,不好意思,release版本应该会跳过该句,不过,如果“Assertion Failed”的话,估计程序是会出问题的。

恐怕,你的使用方式有问题。

能否把调用代码和dll函数代码贴出来一看。


thanks!

我直接调试DLL, 在DEBUG模式下, 竟然提示:

Unhandled exception In err.exe(NTDLL.DLL): 0XC0000005: Access Violation.

继续调试, 
继续提示:
The thread 0X794 has exited with code -1073741819 (0xC0000005)

以前的接口是:
int WINAPI PTSIT(char* pr1, char* pr2, char* pr3
    char* pr4, char* pr5, BYTE bt1, char* pr5,
    char* pr6, BYTE bt2, BYTE bt3, BYTE bt4, char* pr7,
    char* pr8, BYTE bt5, BYTE bt6, BYTE bt7, BYTE bt8, 
    BYTE bt9, BYTE* bt10,BYTE* bt11, BYTE* bt12);

现在改为:
int WINAPI PTSIT(char* pr1, char* pr2, char* pr3
    char* pr4, char* pr5, BYTE bt1, char* pr5,
    char* pr6, BYTE bt2, BYTE bt3, BYTE bt4, char* pr7,
    char* pr8, BYTE bt5, BYTE bt6, BYTE bt7, BYTE bt8, 
    BYTE bt9, BYTE* bt10,BYTE* bt11, BYTE* bt12, char* pt);

只在最后面加上一个参数char* pt, pt字符串最长八个字符



是说此指针与指定堆不符,原因楼上有说明(根运行库的使用有关系),估计是欲在dll内释放exe中分配的内存,或相反。。。建议内存谁分配谁释放。


thanks!

我直接调试DLL, 在DEBUG模式下, 竟然提示:

First-chance exception in err.exe (err.DLL): 0xC0000005: Access Violation.
First-chance exception in err.exe (NTDLL.DLL): 0xC0000005: Access Violation.
The program 'D:\err\Release\err.exe' has exited with code 0 (0x0).

其它程序也没有改什么地方呀!

试一试这个:主工程和DLL工程的都设置为同样的DEBUG Multithreaded DLL或Mutithreaded DLL,project-->settings-->c/c++标签页中的category下拉筐中选code generation,然后在Use Rutime Library中选DEBUG Multithreaded DLL或Mutithreaded DLL。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值