Bool返回值从非托管函数调用到托管函数调用。 [英] Bool return value changing magically from unmanaged to managed function call.

查看:73
本文介绍了Bool返回值从非托管函数调用到托管函数调用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要访问c ++库的ac#应用程序,所以它通过使用c ++ CLI的托管层来实现这一点。


无论如何,在CLI函数调用中,它调用非托管函数它需要一个布尔返回值,但是值会改变!

我走了代码,并且unmanged代码返回false,

但是当我查看托管代码中的变量时,它的返回值

是真的。即使在我将接受该值的变量初始化为
为false之后。没有其他线程访问此代码。任何人都有任何想法吗?

Hi, I have a c# application that needs to access c++ libraries, so it
does this by using a managed layer of c++ CLI.

Anyway, in the CLI function call, that calls the unmanaged function it
expects a boolean return value, which it gets, but the value changes!
I walked throuhg the code, and the unmanged code is returning false,
but when I look at the variable in the managed code it''s return value
it true. Even after I initialized the variable accepting that value
as false. There are no other threads accesing this code. Anyone have
any ideas?

推荐答案

" DaTurk" < mm ****** @ hotmail.comwrote in message

news:11 ********************** @ l53g2000cwa .googlegr oups.com ...
"DaTurk" <mm******@hotmail.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...

无论如何,在CLI函数调用中,它调用非托管函数

需要布尔返回它得到的价值,但价值会发生变化!

我走过代码,无人管的代码返回false,

但是当我看到变量时托管代码它的返回值

它是真的。即使在我将接受该值的变量初始化为
为false之后。没有其他线程访问此代码。任何人有什么想法?

Anyway, in the CLI function call, that calls the unmanaged function it
expects a boolean return value, which it gets, but the value changes!
I walked throuhg the code, and the unmanged code is returning false,
but when I look at the variable in the managed code it''s return value
it true. Even after I initialized the variable accepting that value
as false. There are no other threads accesing this code. Anyone have
any ideas?



这是运行时编组和解组布尔值的方式中的错误,而b / b是本机代码和托管代码之间的边界。


还有其他方法可以解决这个问题,但这一个


bool unManagedFunction(...)

{

bool ok;


//设置好


ok = ...;


//确保累加器的3个高位字节为零

//然后适当地设置其低位字节


_asm xor eax,eax

返回确定;

}


征收单一指令罚款。


问候,


www.ivrforbeginners.com

It''s a bug in the way the runtime marshals and unmarshals booleans across
the boundary between native and managed code.

There are other ways of solving the problem, but this one

bool unManagedFunction(...)
{
bool ok;

// set ok

ok = ...;

// Insure the 3 high order bytes of the accumulator will be zero
// Then set its low order byte appropriately

_asm xor eax, eax
return ok;
}

imposes a single instruction penalty.

Regards,
Will
www.ivrforbeginners.com


2月7日上午9:16,William DePalo [MVP VC ++]"

< willd.no.s ... @ mvps.orgwrote:
On Feb 7, 9:16 am, "William DePalo [MVP VC++]"
<willd.no.s...@mvps.orgwrote:

" DaTurk&qu OT; < mmagd ... @ hotmail.comwrote in message


新闻:11 ********************** @ l53g2000cwa.googlegr oups.com ...
"DaTurk" <mmagd...@hotmail.comwrote in message

news:11**********************@l53g2000cwa.googlegr oups.com...

无论如何,在CLI函数调用中,它调用非托管函数

需要一个布尔值返回值,它得到了,但是值改变了!

我走了代码,无人管的代码返回false,

但是当我查看变量时托管代码它的返回值

是真的。即使在我将接受该值的变量初始化为
为false之后。没有其他线程访问此代码。任何人有什么想法?

Anyway, in the CLI function call, that calls the unmanaged function it
expects a boolean return value, which it gets, but the value changes!
I walked throuhg the code, and the unmanged code is returning false,
but when I look at the variable in the managed code it''s return value
it true. Even after I initialized the variable accepting that value
as false. There are no other threads accesing this code. Anyone have
any ideas?



这是运行时编组和解组布尔值的方式中的一个错误。

本机代码和托管代码之间的边界。


还有其他方法可以解决这个问题,但这一个


bool unManagedFunction(...)

{

bool ok;


//设置好


ok = ...;


//确保累加器的3个高位字节为零

//然后适当地设置其低位字节


_asm xor eax,eax

返回确定;


}


征收单一指令罚款。


问候,

Willwww.ivrforbeginner


It''s a bug in the way the runtime marshals and unmarshals booleans across
the boundary between native and managed code.

There are other ways of solving the problem, but this one

bool unManagedFunction(...)
{
bool ok;

// set ok

ok = ...;

// Insure the 3 high order bytes of the accumulator will be zero
// Then set its low order byte appropriately

_asm xor eax, eax
return ok;

}

imposes a single instruction penalty.

Regards,
Willwww.ivrforbeginner



谢谢回复。我不完全确定我理解这个命令

_asm xor eax,eax足以使用它,你会介意详细说明吗?

在非托管代码中,它已经使用了一个类似的命令,你建议如何使用这个__asm mov eax,100 ??或者这是

问题?

THanks for the reply. I''m not entirely sure I understand this command
_asm xor eax, eax enough to use it, would you mind elaborating on it?
In the unmanaged code, it already uses a similar command, how will the
one you propose effect this one __asm mov eax,100?? Or is this the
problem?


只是抬头,我用了那个命令_asm xor eax,eax,并删除了

另一个,它没有帮助。什么是其他

解决方案?

Just a heads up, I used that command _asm xor eax, eax, and removed
the other one, and it didn''t help. What are some of the other
solutions?


这篇关于Bool返回值从非托管函数调用到托管函数调用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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