运行时检查失败#0 - ESP的值未在功能中正确保存 [英] Run-Time Check Failure #0 - The value of ESP was not properly saved across a function

查看:96
本文介绍了运行时检查失败#0 - ESP的值未在功能中正确保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


我抓住了一个有效的IWebBrowser2对象。

我将它传递给一个应该返回href值的函数IHTMLDocument3对象中的链接标记,这里是函数:

Hi everyone !

I got hold of a valid IWebBrowser2 object.
I am passing it to a function that should return the value of href in a link tag in the IHTMLDocument3 object, here is the function:

展开 | 选择 | Wrap | 行号

推荐答案

此函数返回LPCTSTR,你正在返回一个CString。


我很惊讶你要编译这个。


另外,你没有使用代码中的任何TCHAR映射。也就是说,你应该使用CStringT而不是Cstring。你的文字应该使用TEXT宏等。


我会使用SysAllocString创建BSTR或使用CComBSTR而不是宏。


我认为第4行的类型转换是有道理的。我怀疑绕过IUnknown :: QueryInterface的COM接口上的所有类型转换。
This function returns an LPCTSTR and you are returning a CString.

I''m surprised you are getting this to compile.

Also, you are not using any of the TCHAR mappings in your code. That is, you should use CStringT and not Cstring. Your literals should use the TEXT macro, etc..

I would create the BSTR by using SysAllocString or use CComBSTR rather than a macro.

I assume your typecast in line 4 makes sense. I am susicious of all typecasts on COM interfaces that bypass IUnknown::QueryInterface.


Hi weaknessforcats,

感谢您的回复。


但是你不应该对代码编译感到惊讶,因为CString类有几个重载操作符将CString转换为LPCTSTR。

CString基本上是一个CStringT in事实上它实现了它,CStringT是一个模板类。


我不认为我得到的运行时错误与BSTR的创建方式有任何关系,虽然你对CComQIPtr和CComPtr的使用存在疑问,但它们的存在是为了使代码更清晰,更具可读性和无bug,引用会自动添加和释放。


这是完整运行我得到的时间错误:
运行时检查失败#0 - ESP的值未在函数调用中正确保存。这通常是调用使用一个调用约定声明的函数的结果,函数指针使用不同的调用约定声明。


我在编译时尝试了不同的调用约定像/ Gd和/ Gz这样的时间,我也试图用__stdcall声明这个函数到目前为止没有成功。


我的选项用完了,有什么想法吗?


Andrea
Hi weaknessforcats,
thank you for your reply.

However you shouldn''t be surprised the code compiles since the CString class has several overload operators that transform a CString to a LPCTSTR.
Farther more a CString is basically a CStringT in fact it implements it, CStringT is a template class.

I don''t think the run-time error i am getting has any thing to do with the way a BSTR is created, and although you are suspicious regarding the use of CComQIPtr and CComPtr they exist to keep the code cleaner, more readable and bug free, references are automatically added and released.

This is the full run-time error i am getting:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

I have tried with different Calling Conventions at compile time like /Gd and /Gz, and also i tried to declared the function with __stdcall no success so far.

I am running out of options, any ideas ?

Andrea


展开 | 选择 | Wrap | 行号


这篇关于运行时检查失败#0 - ESP的值未在功能中正确保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆