创建一个可以从纯unmanagedcode使用的包装托管dll [英] create a wrapped managed dll that can be used from pure unmanagedcode

查看:38
本文介绍了创建一个可以从纯unmanagedcode使用的包装托管dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我正在尝试创建一个内部使用托管类型的dll,但是

暴露了一个普通的非托管接口。所有托管的东西都应该是看不见的。这样我就可以使用来自

纯粹的非托管代码的dll(例如从该dll中的类继承)。

就是这样的。我听到了ManWarp试图接近的东西。


如果有可能,我怎么能这样做。也许有一个小小的

示例项目?

Hello,

I am trying to create a dll that internally uses managed types but
exposes a plain unmanaged interface. All the managed stuff shall be
"wrapped out of sight". So that I would be able to use that dll from
pure unmanaged code (for example inherit from classes in that dll). Is
something like that possible. I heared something called ManWarp tried
that approach.

If it is possible, how can I do that. Maybe there is a small litttle
sample project around ?

推荐答案

您不能使用纯托管代码中的托管类,除非他们是通过COM互操作暴露给非托管代码的



----------------

-Atul,Sky Software http://www.ssware.com

Shell MegaPack For .Net& ActiveX

Windows资源管理器GUI控件

&

快速启动像Appbars,MSN / Office2003样式弹出窗口,

系统托盘图标和快捷方式/互联网快捷方式

----------------


" bonk" < SC ****************** @ gmx.de>在消息中写道

news:uL **************** @ TK2MSFTNGP14.phx.gbl ...
You cannot use Managed classes from pure managed code unless they are
exposed to unmanaged code via COM interop

----------------
-Atul, Sky Software http://www.ssware.com
Shell MegaPack For .Net & ActiveX
Windows Explorer GUI Controls
&
Quick-Launch Like Appbars, MSN/Office2003 Style Popups,
System Tray Icons and Shortcuts/Internet Shortcuts
----------------

"bonk" <sc******************@gmx.de> wrote in message
news:uL****************@TK2MSFTNGP14.phx.gbl...
你好,

我正在尝试创建一个内部使用托管类型的dll,但是暴露了一个简单的非托管接口。所有管理的东西都应该包裹在视线中。这样我就可以使用纯粹的非托管代码中的dll(例如从该dll中的类继承)。类似
的东西是可能的。我听到了ManWarp尝试过这种方法的东西。

如果有可能,我怎么能这样做。也许周围有一个小小的示例项目?
Hello,

I am trying to create a dll that internally uses managed types but exposes
a plain unmanaged interface. All the managed stuff shall be "wrapped out
of sight". So that I would be able to use that dll from pure unmanaged
code (for example inherit from classes in that dll). Is something like
that possible. I heared something called ManWarp tried that approach.

If it is possible, how can I do that. Maybe there is a small litttle
sample project around ?



" bonk" < SC ****************** @ gmx.de>在留言中写道

新闻:uL **************** @ TK2MSFTNGP14.phx.gbl ...
"bonk" <sc******************@gmx.de> wrote in message
news:uL****************@TK2MSFTNGP14.phx.gbl...
我正在尝试创建一个内部使用托管类型的DLL,但是暴露了一个简单的非托管接口。所有管理的东西都应该包裹在视线中。这样我就可以使用纯粹的非托管代码中的dll(例如从该dll中的类继承)。类似
的东西是可能的。我听到了ManWarp尝试过这种方法的东西。

如果有可能,我怎么能这样做。也许周围有一个小小的示例项目?
I am trying to create a dll that internally uses managed types but exposes
a plain unmanaged interface. All the managed stuff shall be "wrapped out
of sight". So that I would be able to use that dll from pure unmanaged
code (for example inherit from classes in that dll). Is something like
that possible. I heared something called ManWarp tried that approach.

If it is possible, how can I do that. Maybe there is a small litttle
sample project around ?




是的,这是可能的。对你的问题的简短回答是使用'它只是

作品''" (又名IJW)


见这里

http://msdn.microsoft.com/library/de...nunmancode.asp


和这里

http://msdn.microsoft.com/msdnmag/is...5/default.aspx


了解详情。


如果您不知道托管C ++(又称MC ++即将被重命名为C ++ / CLI)是

唯一符合CLS的语言MS允许您在同一个可执行组件甚至同一模块中混合托管和

非托管代码。所以你可以做的是编写非托管(本机)代码,调用托管的

代码。


你可以使用


#pragma管理





#pragma unmanaged


分隔符用于标记原生代码和

代码的延伸。当本机函数调用托管函数时,编译器处理

进行转换所需的thunking。


也就是说,存在问题。使用混合模式DLL,你必须知道

of。详情请见这里。

http://msdn.microsoft.com/library/de...omixedmode.asp


如果你可以等两周,直到VS2005发布,如果你可以专门定位

..Net v2.0,你可能会有更轻松的时间。


问候,






Yes, it''s possible. The short answer to your question is "Use ''It just
Works''" (aka IJW)

See here

http://msdn.microsoft.com/library/de...nunmancode.asp

and here

http://msdn.microsoft.com/msdnmag/is...5/default.aspx

for the details.

In case you don''t know Managed C++ (aka MC++ soon to be renamed C++/CLI) is
the only CLS compliant language out of MS that allows you to mix managed and
unmanaged code in the same executable component or even the same module. So
what you can do is write unmanaged (native) code which calls into managed
code.

You can use

#pragma managed

and

#pragma unmanaged

delimiters to mark the stretches of code that are native and those that are
not. When a native function calls into a managed one, the compiler handles
the thunking necessary to make the transition.

That said, there are "issues" with mixed-mode DLLs that you must be aware
of. See here for the details.

http://msdn.microsoft.com/library/de...omixedmode.asp

If you can wait the two weeks till VS2005 is released, and if you can target
..Net v2.0 exclusively, you may have an easier time of it.

Regards,
Will



William DePalo [MVP VC ++] schrieb:
William DePalo [MVP VC++] schrieb:
bonk < SC ****************** @ gmx.de>在消息中写道
新闻:uL **************** @ TK2MSFTNGP14.phx.gbl ...
"bonk" <sc******************@gmx.de> wrote in message
news:uL****************@TK2MSFTNGP14.phx.gbl...
我正在尝试创建一个内部使用托管类型的DLL,但是暴露了一个简单的非托管接口。所有管理的东西都应该包裹在视线中。这样我就可以使用纯粹的非托管代码中的dll(例如从该dll中的类继承)。类似
的东西是可能的。我听到了ManWarp尝试过这种方法的东西。

如果有可能,我怎么能这样做。也许周围有一个小小的示例项目?
I am trying to create a dll that internally uses managed types but exposes
a plain unmanaged interface. All the managed stuff shall be "wrapped out
of sight". So that I would be able to use that dll from pure unmanaged
code (for example inherit from classes in that dll). Is something like
that possible. I heared something called ManWarp tried that approach.

If it is possible, how can I do that. Maybe there is a small litttle
sample project around ?



是的,这是可能的。对你的问题的简短回答是使用'它只是
工程''' (又名IJW)

看到这里

http://msdn.microsoft.com/library/de...nunmancode.asp

http://msdn.microsoft.com/msdnmag/is...5/default.aspx

了解详情。

万一你不知道托管C ++(又称MC ++即将被重命名为C ++ / CLI)是MS中唯一一种兼容CLS的语言,它允许您在同一个可执行组件中混合托管代码和
非托管代码,或者甚至是同一个模块。所以你可以做的就是编写非托管(本机)代码,调用托管的代码。

你可以使用

#pragma managed



#pragma unmanaged

分隔符标记原生代码和
代码。当本机函数调用托管函数时,编译器会处理进行转换所需的thunking。

也就是说,存在问题。使用混合模式DLL,你必须知道。详情请见这里。

http://msdn.microsoft.com/library/de...omixedmode.asp

如果你可以等两个几个星期,直到VS2005发布,如果你可以专门定位
.Net v2.0,你可能会有更轻松的时间。

问候,



Yes, it''s possible. The short answer to your question is "Use ''It just
Works''" (aka IJW)

See here

http://msdn.microsoft.com/library/de...nunmancode.asp

and here

http://msdn.microsoft.com/msdnmag/is...5/default.aspx

for the details.

In case you don''t know Managed C++ (aka MC++ soon to be renamed C++/CLI) is
the only CLS compliant language out of MS that allows you to mix managed and
unmanaged code in the same executable component or even the same module. So
what you can do is write unmanaged (native) code which calls into managed
code.

You can use

#pragma managed

and

#pragma unmanaged

delimiters to mark the stretches of code that are native and those that are
not. When a native function calls into a managed one, the compiler handles
the thunking necessary to make the transition.

That said, there are "issues" with mixed-mode DLLs that you must be aware
of. See here for the details.

http://msdn.microsoft.com/library/de...omixedmode.asp

If you can wait the two weeks till VS2005 is released, and if you can target
.Net v2.0 exclusively, you may have an easier time of it.

Regards,
Will



我比Atul的One更喜欢你的回答。谢谢。我马上就会看看

吧。是的,我们可以专门针对.net 2.0,是的,我们将使用vs b $ b使用vs 2005.我现在正在使用c ++ / CLI和vs beta beta 2.


Will,


有一件事我还是听不懂。它与如何将
包装在该dll中的托管内容有关。你说我会写入

非托管(本机)代码,它会调用托管代码。调用托管代码的那些

非托管类将使用

__declspec(dllexport)正确公开?如果是这样那些非托管包装类

将需要将一些私有成员保存到托管类

(gcroot< ManagedType ^> m_mythingy),我将需要声明它就像这样

在标题中。当我想从另一个

普通的非托管项目中使用dll(带有它的lib)时,我需要包含它的标题和它

现在将有gcroot< ManagedType ^> m_mythingy;在课堂的某个地方

声明。因为我的项目没有/ clr,所以不可能。

我该如何包装它?


I like your answer better than the One from Atul. Thx. I will look into
it right away. Yes we can target .net 2.0 exclusively and yes we will
use vs 2005. I am working with c++/CLI and vs 2005 beta 2 right now.

Will,

there is one thing I still cannot understand. It has to do with how to
wrap the managed stuff away in that dll. You say I would "write
unmanaged (native) code which calls into managed code" and some of those
unmanaged classes that call into managed code will be exposed using
__declspec(dllexport) correct? If so those unmanaged wrapper classes
will need to hold some private members to the managed classes
(gcroot <ManagedType^> m_mythingy) and I will need to declare it as such
in the header. When I want to use the dll (with its lib) from another
plain unmanaged project I will need to include the header for it and it
will now have gcroot <ManagedType^> m_mythingy; somewhere in the class
declaration. Wich is not possible since my project does not have /clr.
How am I supposed to wrap that away ?


这篇关于创建一个可以从纯unmanagedcode使用的包装托管dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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