C ++ / CLI,Unmanaged to Managed callback,不使用网桥或固定指针。

C ++ / CLI,Unmanaged to Managed callback,不使用网桥或固定指针。

问题描述:




我有一个相当有趣的问题。我有一个无法管理的c ++类

需要通过回调将信息传递给托管的c ++,

在托管的c ++上提供一层c#ultimatley retreiving

数据。目前所有的c ++代码仍然在.NET 1.1中,因此我们使用包含在_gc c ++类中的_nogc桥类来获得
,以便

为此提供便利互操作。


但是我们已经把所有不是c ++的东西都转换成了.NET 2.0,并且很乐意将b ++转换为c ++,但是我是不知道如何克服这个问题。我的问题......


1.)C ++ / CLI不支持这种_nogc桥类的想法。


2.)我需要有这个指针用于

应用程序的生命周期,这意味着我需要将其固定,这是一个非常糟糕的想法,因为它将被锁定在堆积为

持续时间。


所以我不知道如何克服这个问题。任何帮助都会非常值得赞赏。

Hi,

I have a rather interesting problem. I have a unmanged c++ class
which needs to communicate information to managed c++ via callbacks,
with a layer of c# on top of the managed c++ ultimatley retreiving the
data. Presently all of the c++ code is still in .NET 1.1, so we''re
using a _nogc bridge class wrapped in a _gc c++ class in order to
facilitate this interop.

But we''ve converted everything not c++ to .NET 2.0 and would love to
convert the c++ as well, but I''m not sure how to overcome this
problem. My issues...

1.) C++/CLI does not support this _nogc bridge class idea.

2.)I would need to have this pointer around for the life of the
application, which means I would need to pin it, which is a
ridiculously bad idea considering it will be locked on the heap for
the duration.

So I''m not sure how to overcome this. Any help would be greatly
appreciated.

我有一个相当有趣的问题。我有一个无法管理的c ++类
I have a rather interesting problem. I have a unmanged c++ class

需要通过回调将信息传递给托管c ++,

在c#之上有一层c#托管c ++ ultimatley检索

数据。目前所有的c ++代码仍然在.NET 1.1中,因此我们使用包含在_gc c ++类中的_nogc桥类来获得
,以便

为此提供便利互操作。


但是我们已经把所有不是c ++的东西都转换成了.NET 2.0,并且很乐意将b ++转换为c ++,但是我是不知道如何克服这个问题。我的问题......


1.)C ++ / CLI不支持这种_nogc桥类的想法。


2.)我需要有这个指针用于

应用程序的生命周期,这意味着我需要将其固定,这是一个非常糟糕的想法,因为它将被锁定在堆积为

的持续时间。
which needs to communicate information to managed c++ via callbacks,
with a layer of c# on top of the managed c++ ultimatley retreiving the
data. Presently all of the c++ code is still in .NET 1.1, so we''re
using a _nogc bridge class wrapped in a _gc c++ class in order to
facilitate this interop.

But we''ve converted everything not c++ to .NET 2.0 and would love to
convert the c++ as well, but I''m not sure how to overcome this
problem. My issues...

1.) C++/CLI does not support this _nogc bridge class idea.

2.)I would need to have this pointer around for the life of the
application, which means I would need to pin it, which is a
ridiculously bad idea considering it will be locked on the heap for
the duration.






首先,您是否尝试使用/ clr:oldSyntax构建C ++代码?

这应该可以让你在没有做任何事情的情况下移植到.NET2.0和VC2005,

除了这里或那里的调整外还可以。


我不确定我是否正确理解(1)。在C ++ / CLI中,您仍然可以围绕本机类包装一个

托管类。你的意思是其他的吗?


-


亲切的问候,

Bruno van Dooren
br ************* *********@hotmail.com

仅删除_nos_pam

Hi,

First of all, have you tried building your C++ code with /clr:oldSyntax?
That should enable you to port to .NET2.0 and VC2005 without doing anything,
save for a tweak here or there maybe.

I am not sure I understand (1) correctly. In C++/CLI you can still wrap a
managed class around a native class. Do you mean somehing else?

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"


2月9日,凌晨1点04分,Bruno van Dooren [MVP VC ++]"

< bruno_nos_pam_van_doo ... @ hotmail.comwrote:
On Feb 9, 1:04 am, "Bruno van Dooren [MVP VC++]"
<bruno_nos_pam_van_doo...@hotmail.comwrote:

我有一个相当有趣的问题。我有一个无法管理的c ++类

需要通过回调将信息传递给托管的c ++,

在托管的c ++上提供一层c#ultimatley retreiving

数据。目前所有的c ++代码仍然在.NET 1.1中,因此我们使用包含在_gc c ++类中的_nogc桥类来获得
,以便

为此提供便利互操作。
I have a rather interesting problem. I have a unmanged c++ class
which needs to communicate information to managed c++ via callbacks,
with a layer of c# on top of the managed c++ ultimatley retreiving the
data. Presently all of the c++ code is still in .NET 1.1, so we''re
using a _nogc bridge class wrapped in a _gc c++ class in order to
facilitate this interop.


但是我们已经把所有不是c ++的东西都转换成了.NET 2.0,并且很乐意将b ++转换成c ++。 ,但我不知道如何克服这个问题。我的问题...
But we''ve converted everything not c++ to .NET 2.0 and would love to
convert the c++ as well, but I''m not sure how to overcome this
problem. My issues...


1.)C ++ / CLI不支持这个_nogc桥类的想法。
1.) C++/CLI does not support this _nogc bridge class idea.


2.)我需要在

应用程序的生命周期中使用此指针,这意味着我会需要固定它,这是一个非常糟糕的想法,因为它将被锁定在堆上,持续时间为


2.)I would need to have this pointer around for the life of the
application, which means I would need to pin it, which is a
ridiculously bad idea considering it will be locked on the heap for
the duration.



您好,


首先,您是否尝试使用/ clr:oldSyntax构建C ++代码?

这应该可以让你在没有做任何事情的情况下移植到.NET2.0和VC2005,

除了这里或那里的调整外还可以。


我不确定我是否正确理解(1)。在C ++ / CLI中,您仍然可以围绕本机类包装一个

托管类。你的意思是其他的吗?


-


亲切的问候,

Bruno van Dooren

bruno_nos_pam_van_doo ... @ hotmail.com

仅删除_nos_pam - 隐藏引用的文字 -


- 显示引用的文字 -


Hi,

First of all, have you tried building your C++ code with /clr:oldSyntax?
That should enable you to port to .NET2.0 and VC2005 without doing anything,
save for a tweak here or there maybe.

I am not sure I understand (1) correctly. In C++/CLI you can still wrap a
managed class around a native class. Do you mean somehing else?

--

Kind regards,
Bruno van Dooren
bruno_nos_pam_van_doo...@hotmail.com
Remove only "_nos_pam"- Hide quoted text -

- Show quoted text -



真的吗?我的印象是它不被支持。你能不能给我一个CLI语法的例子吗?

Really? I was under the impression it wasn''t supported. Would you
mind showing me an example with CLI syntax?


DaTurk写道:
DaTurk wrote:

真的吗?我的印象是它不被支持。你能不能给我一个CLI语法的例子吗?
Really? I was under the impression it wasn''t supported. Would you
mind showing me an example with CLI syntax?

http://tweakbits.com/UnmanagedToManagedCallback.cpp
http://tweakbits.com/ManagedToUnmanagedCallback.cpp


这就是你如何连接托管和非托管代码。


你应该只在很短的时间内固定一个对象,而

您正在访问或编组数据。在任何情况下你都不应该在应用程序的整个生命周期内保留一个固定的对象。


你不能再将一个嵌套的非托管类放在一个托管的类中,但是

这只是语法和风格。从技术的角度来看,如果没有嵌套类,你几乎没有什么可以实现的,

归功于公共保护和内部访问修饰符。 />

MC ++中没有任何东西可以让C ++ / CLI不再做了(嵌套不是

真的是一个主要功能,只是为了方便)。他们只使用不同的

语法。你是如何解决MC ++代码中的固定的?规则是在C ++ / CLI中相同的

。你是如何桥接非托管和托管类的?你用
在C ++ / CLI中做了完全相同的语法。


Tom

http://tweakbits.com/UnmanagedToManagedCallback.cpp
http://tweakbits.com/ManagedToUnmanagedCallback.cpp

This is how you bridge managed and unmanaged code.

You should only pin an object for a very brief period of time, while
you''re accessing or marshalling data. Under no circumstances should you
keep an object pinned for the entire lifetime of the application.

You can no longer put a nested unmanaged class inside a managed one, but
that''s just syntax and style. From the technical standpoint, there''s
practically nothing that you can''t achieve without nested classes,
thanks to the public protected and internal access modifiers.

There is nothing in MC++ that C++/CLI can not do anymore (nesting is not
really a major feature, just a convenience). They just use a different
syntax. How did you solve pinning in your MC++ code? The rules are the
same in C++/CLI. How did you bridge unmanaged and managed classes? You
do exactly the same in C++/CLI, with a different syntax.

Tom