青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

C++ Programmer's Cookbook

{C++ 基礎(chǔ)} {C++ 高級} {C#界面,C++核心算法} {設(shè)計模式} {C#基礎(chǔ)}

Native c++ 和Managed 的 interop

4種方法:

There are four main ways to do interop in .NET between the managed and native worlds. COM interop can be accomplished using Runtime Callable Wrappers (RCW) and COM Callable Wrappers (CCW). The common language runtime (CLR) is responsible for type marshaling (except in the rare scenarios where a custom marshaler is used) and the cost of these calls can be expensive. You need to be careful that the interfaces are not too chatty; otherwise a large performance penalty could result. You also need to ensure that the wrappers are kept up to date with the underlying component. That said, COM interop is very useful for simple interop scenarios where you are attempting to bring in a large amount of native COM code.

The second option for interop is to use P/Invoke. This is accomplished using the DllImport attribute, specifying the attribute on the method declaration for the function you want to import. Marshaling is handled according to how it has been specified in the declaration. However, DllImport is only useful if you have code that exposes the required functions through a DLL export.

When you need to call managed code from native code, CLR hosting is an option. In such a scenario, the native application has to drive all of the execution: setting up the host, binding to the runtime, starting the host, retrieving the appropriate AppDomain, setting up the invocation context, locating the desired assembly and class, and invoking the operation on the desired class. This is definitely one of the most robust solutions in terms of control over what and when things happen, but it is also incredibly tedious and requires a lot of custom code.

The fourth option, and quite possibly the easiest and the most performant, is to use the interop capabilities in C++. By throwing the /clr switch, the compiler generates MSIL instead of native machine code. The only code that is generated as native machine code is code that just can't be compiled to MSIL, including functions with inline asm blocks and operations that use CPU-specific intrinsics such as Streaming SIMD Extensions (SSE). The /clr switch is how the Quake II port to .NET was accomplished. The Vertigo software team spent a day porting the original C code for the game to code that successfully compiled as C++ and then threw the /clr switch. In no time they were up and running on the .NET Framework. Without adding any additional binaries and simply by including the appropriate header files, managed C++ and native C++ can call each other without any additional work on the part of the developer. The compiler handles the creation of the appropriate thunks to go back and forth between the two worlds.

posted on 2006-08-17 16:26 夢在天涯 閱讀(2267) 評論(5)  編輯 收藏 引用 所屬分類: CPlusPlusC#/.NETManage c++ /CLIVS2005/2008

評論

# re: Native c++ 和Managed 的 interop 2006-08-17 16:28 夢在天涯

msdn enlish:http://msdn.microsoft.com/msdnmag/issues/04/05/VisualC2005/default.aspx#S1  回復  更多評論   

# re: Native c++ 和Managed 的 interop 2006-08-17 16:39 夢在天涯

1 使用RCW和CCW來訪問
是否可以在 .NET 框架程序中使用 COM 對象?
是。您現(xiàn)在部署的任何 COM 組件都可以在托管代碼中使用。通常情況下,所需的調(diào)整是完全自動進行的。

特別是,可以使用運行時可調(diào)用包裝 (RCW) 從 .NET 框架訪問 COM 組件。此包裝將 COM 組件提供的 COM 接口轉(zhuǎn)換為與 .NET 框架兼容的接口。對于 OLE 自動化接口,RCW 可以從類型庫中自動生成;對于非 OLE 自動化接口,開發(fā)人員可以編寫自定義 RCW,手動將 COM 接口提供的類型映射為與 .NET 框架兼容的類型。

是否可以在 COM 程序中使用 .NET 框架組件?
是。您現(xiàn)在創(chuàng)建的托管類型都可以通過 COM 訪問。通常情況下,所需的配置是完全自動進行的。托管開發(fā)環(huán)境的某些新特性不能在 COM 中訪問。例如,不能在 COM 中使用靜態(tài)方法和參數(shù)化構(gòu)造函數(shù)。一般,提前確定給定類型所針對的用戶是一種較好的辦法。如果類型需要在 COM 中使用,您將被限制在使用 COM 可訪問的特性。

默認情況下,托管類型可能是可見的,也可能是不可見的,這由用于編寫托管類型的語言決定。

特別是,可以使用 COM 可調(diào)用包裝 (CCW) 從 COM 訪問 .NET 框架組件。這與 RCW(請參閱上一個問題)相似,但它們的方向相反。同樣,如果 .NET 框架開發(fā)工具不能自動生成包裝,或者如果自動方式不是您所需要的,則可以開發(fā)自定義的 CCW。

  回復  更多評論   

# re: Native c++ 和Managed 的 interop 2006-08-17 16:53 夢在天涯

2 使用p\invoke方法
是否可以在 .NET 框架程序中使用 Win32 API?
是。使用 P/Invoke,.NET 框架程序可以通過靜態(tài) DLL 入口點的方式來訪問本機代碼庫。

下面是 C# 調(diào)用 Win32 MessageBox 函數(shù)的示例:

using System;
using System.Runtime.InteropServices;

class MainApp
{
[DllImport("user32.dll", EntryPoint="MessageBox")]
public static extern int MessageBox(int hWnd, String strMessage, String strCaption, uint uiType);

public static void Main()
{
MessageBox( 0, "您好,這是 PInvoke!", ".NET", 0 );
}
}
  回復  更多評論   

# re: Native c++ 和Managed 的 interop 2006-08-17 16:57 夢在天涯

3 使用 CLR hosting  回復  更多評論   

# re: Native c++ 和Managed 的 interop 2006-08-17 16:58 夢在天涯

4 修改clr編譯選項  回復  更多評論   

公告

EMail:itech001#126.com

導航

統(tǒng)計

  • 隨筆 - 461
  • 文章 - 4
  • 評論 - 746
  • 引用 - 0

常用鏈接

隨筆分類

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1814982
  • 排名 - 5

最新評論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
      <noscript id="pjuwb"></noscript>
            <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
              <dd id="pjuwb"></dd>
              <abbr id="pjuwb"></abbr>
              亚洲欧美日韩国产中文在线| 亚洲最新视频在线播放| 久久久久这里只有精品| 亚洲一区二区少妇| 日韩一区二区免费高清| 91久久在线播放| 欧美成人午夜剧场免费观看| 久久综合给合| 欧美日韩国产成人精品| 欧美激情中文字幕一区二区| 欧美a级在线| 亚洲国产导航| 99热免费精品| 亚洲视频精选在线| 亚洲欧美第一页| 久久久91精品国产一区二区三区| 久久免费少妇高潮久久精品99| 美女爽到呻吟久久久久| 欧美日韩精品国产| 国产日韩精品一区二区三区| 娇妻被交换粗又大又硬视频欧美| 亚洲第一网站免费视频| 中文在线不卡| 六月婷婷一区| 中日韩午夜理伦电影免费| 久久爱www久久做| 欧美日本国产视频| 激情丁香综合| 亚洲欧美欧美一区二区三区| 狂野欧美激情性xxxx| 夜夜嗨av一区二区三区网页| 久久人人爽人人爽爽久久| 欧美性视频网站| 91久久线看在观草草青青| 久久精品欧美| 亚洲午夜精品视频| 欧美精品高清视频| 永久免费毛片在线播放不卡| 亚洲免费在线视频| 亚洲欧洲精品一区二区| 久久国产精品久久国产精品| 国产精品福利在线观看| 亚洲青涩在线| 噜噜噜久久亚洲精品国产品小说| 亚洲欧美久久久| 欧美三区免费完整视频在线观看| 在线观看欧美激情| 久久精品日韩欧美| 亚洲一区二区成人| 欧美三级日本三级少妇99| 尤物九九久久国产精品的特点 | 亚洲精品偷拍| 毛片精品免费在线观看| 亚洲永久在线| 国产精品美女久久| 亚洲一区二区四区| 亚洲美女av黄| 欧美激情一区二区在线| 亚洲高清资源| 亚洲第一中文字幕| 欧美11—12娇小xxxx| 亚洲第一网站| 亚洲国产一区二区三区青草影视 | 麻豆国产精品777777在线| 一区二区三区波多野结衣在线观看| 欧美va亚洲va香蕉在线| 亚洲高清一区二区三区| 久久亚洲视频| 老司机一区二区三区| 在线观看欧美精品| 亚洲高清免费| 欧美乱大交xxxxx| 中文国产一区| 亚洲尤物在线视频观看| 国产精品欧美日韩一区二区| 欧美一区二区三区在线观看视频| 亚洲综合视频一区| 国产亚洲精品一区二555| 久久久精彩视频| 久久一区二区三区超碰国产精品| 在线精品视频一区二区| 亚洲电影天堂av| 欧美激情一区二区| 亚洲天堂成人| 久久aⅴ国产欧美74aaa| 亚洲成色777777女色窝| 亚洲精品小视频| 国产精品视频一区二区三区| 久久精品99国产精品| 美脚丝袜一区二区三区在线观看 | 欧美高清视频免费观看| 欧美人与性动交cc0o| 午夜精品999| 久久精品女人| 一区二区三区高清| 欧美在线观看一二区| 亚洲精品一区二区三区樱花| 一区二区三区鲁丝不卡| 国产区日韩欧美| 亚洲日本一区二区| 国产亚洲一区二区三区在线播放| 欧美激情一区二区三区蜜桃视频| 国产精品豆花视频| 欧美国产日产韩国视频| 国产精品久久久久永久免费观看 | 亚洲国产高清高潮精品美女| 日韩视频二区| 在线观看av不卡| 亚洲免费视频在线观看| 亚洲第一色在线| 亚洲欧美视频一区| 亚洲人成网站色ww在线| 亚洲欧美国内爽妇网| 日韩一二三在线视频播| 久久精品国产欧美亚洲人人爽| 99国产精品一区| 香蕉视频成人在线观看| 在线观看视频一区二区| 亚洲高清精品中出| 欧美r片在线| 国产嫩草影院久久久久| 亚洲人成网站色ww在线| 国产在线精品一区二区夜色| 亚洲国产精品123| 国产欧美日韩免费| 日韩一级网站| 亚洲精品在线一区二区| 久久精品人人做人人爽| 亚洲一区二区三区免费在线观看| 欧美一级理论片| 午夜激情综合网| 国产精品看片你懂得| 99这里只有久久精品视频| 亚洲九九九在线观看| 可以看av的网站久久看| 狂野欧美一区| 极品少妇一区二区三区精品视频| 欧美影视一区| 久久免费视频一区| 国产一在线精品一区在线观看| 亚洲男人第一av网站| 午夜精品久久久久| 国产精品v日韩精品v欧美精品网站| 亚洲欧洲三级电影| 亚洲免费高清视频| 欧美欧美在线| 日韩亚洲一区二区| 一区二区三区高清| 国产精品免费网站| 午夜精品久久久久| 久久久xxx| 在线成人激情黄色| 奶水喷射视频一区| 亚洲精品网站在线播放gif| 一区二区三区免费观看| 欧美日韩网站| 亚洲免费视频中文字幕| 久久精品国产亚洲5555| 黑丝一区二区| 欧美成人免费观看| 在线一区亚洲| 久久久精品动漫| 亚洲精品一区久久久久久| 欧美激情一区三区| 中文日韩在线视频| 久久国产主播| 亚洲每日在线| 国产精品人成在线观看免费| 欧美一区二区三区四区在线| 久久综合网络一区二区| 亚洲日本乱码在线观看| 欧美色区777第一页| 欧美在线观看视频一区二区| 欧美激情二区三区| 午夜精品福利电影| 亚洲高清av在线| 欧美午夜精品久久久久久超碰| 欧美一区国产二区| 欧美aaa级| 亚洲色图综合久久| 欧美日韩成人网| 久久精品一本| 在线视频亚洲一区| 免费人成网站在线观看欧美高清 | 久久久免费精品| 日韩亚洲精品电影| 亚洲已满18点击进入久久| 另类国产ts人妖高潮视频| 91久久在线| 麻豆freexxxx性91精品| 亚洲在线电影| 亚洲日本欧美天堂| 国内成人精品视频| 欧美日韩综合视频| 久久综合999| 欧美在线资源| 亚洲一区二区在线免费观看| 亚洲成人在线视频网站| 久久久久看片| 欧美一区二区免费视频|