为什么 C++/CLI 中的内联汇编会产生可怕的问题?
我在 C++/CLI 中使用内联汇编。事实上,可怕的问题可能是我观察到的一个错误。 我将向量从一个函数调用传递到另一个函数调用。如果我在被调用函数中注释 _asm{...some assembly code here} 的整个代码片段,其中使用了从其他函数提供给它的向量,那么整个向量就没有问题并成功复制到被调用函数的参数以正确的方式。
但是如果 uncmment _asm{} 我的意思是如果我在被调用的函数中使用 _asm{} 补丁,它会损坏对象的整个向量,事实上整个对象会损坏,其中包含向量和其他字符串数据,并且它只显示对象内的每个数据,例如 npos=4294967295 。
它是什么?为什么会这样呢?是 CLI 造成问题还是我使用内联 asm 的方式错误?
请帮助我,因为我被困在这里。
strParamType = strReturnType;
if(strParamType.find("IDispatch")!=string::npos)
{
IDispatch* pIDispatch;
_asm
{
mov esi,esp
lea eax,[pIDispatch]
push eax
}
}
在这里,如果我在 _asm{} 内根本不写任何内容,即使出现我描述的问题。
问候 乌斯曼
I am using Inline asm in C++/CLI. Horrible problem infact could be a bug I obsereved.
I passed vector from one function call to another. If I comment the whole code snippet of _asm{....some assembly code here} inside the called function where vector used which are provided to it from other function, then no problem whole vector gets fine and copied to argument of called function successfully in correct manner.
But If uncmment _asm{} I mean if I use _asm{} patch in called function , it corrupts the whole vectors of objects infact whole object corrupts which contains vectors and other strings data and it just shows for every data inside object like npos=4294967295.
What is it? Why this is so? Is CLI creating problem or I am using inline asm i wrong way?
Kindly help me out , as I am stuck here.
strParamType = strReturnType;
if(strParamType.find("IDispatch")!=string::npos)
{
IDispatch* pIDispatch;
_asm
{
mov esi,esp
lea eax,[pIDispatch]
push eax
}
}
Here If I dont write anything at all inside _asm{} even then problem occurs which I described.
Regards
Usman
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您提供的源代码中,我无法完全猜测您打算做什么,但我有一些观察结果:
_asm
时,您需要遵守一组规则。例如,请参阅Microsoft 的建议。pIDispatch
。我不知道您的实际代码中接下来的内容,但汇编代码获取堆栈上指针的地址,并将其再次存储在堆栈中。这会带来麻烦,除非您的代码尝试初始化指针。但在 if 子句之后,指针将超出范围!From the source you provide I cannot quite guess what you intend to do, but I'd have a few observations:
_asm
in a .NET environment you need to adhere to a set of rules. Refer to, for instance, Microsoft's advice.pIDispatch
. I don't know what follows in your real code, but the assembler code takes the address of the pointer on your stack, and stores it on stack again. That is calling for trouble, unless your code tries to initialize the pointer. But after the if-clause, the pointer will be out of scope!