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

C++ Programmer's Cookbook

{C++ 基礎} {C++ 高級} {C#界面,C++核心算法} {設計模式} {C#基礎}

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 夢在天涯 閱讀(2274) 評論(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 對象?
是。您現在部署的任何 COM 組件都可以在托管代碼中使用。通常情況下,所需的調整是完全自動進行的。

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

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

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

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

  回復  更多評論   

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

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

下面是 C# 調用 Win32 MessageBox 函數的示例:

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

導航

統計

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

常用鏈接

隨筆分類

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1816914
  • 排名 - 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>
              欧美日韩国产bt| 国产精品久久久久aaaa九色| 国产综合久久久久久鬼色| 午夜欧美电影在线观看| 亚洲一区二区三区免费观看| 欧美午夜在线一二页| 亚洲欧美日韩国产精品| 亚洲免费视频成人| 国产视频久久久久| 裸体丰满少妇做受久久99精品| 久久国产精品久久国产精品| 激情视频亚洲| 91久久精品国产91久久性色tv| 欧美理论在线播放| 亚洲午夜黄色| 欧美一区二区三区久久精品茉莉花 | 91久久夜色精品国产九色| 欧美激情成人在线视频| 欧美日韩第一区日日骚| 性色av一区二区三区| 久久国产精品一区二区三区四区| 在线观看日韩www视频免费| 亚洲精品免费在线| 国产精品一卡二卡| 欧美激情一区二区三区在线| 欧美日韩国产一级| 久久精品中文字幕免费mv| 毛片基地黄久久久久久天堂| 亚洲一区二区高清| 久久久久久久999| 亚洲香蕉伊综合在人在线视看| 欧美在线观看www| 日韩一区二区高清| 久久爱www久久做| 在线视频你懂得一区| 小处雏高清一区二区三区| 亚洲精品乱码久久久久久| 先锋a资源在线看亚洲| 亚洲精选一区二区| 久久精品卡一| 亚洲欧美日韩专区| 欧美福利精品| 免费视频一区| 国产目拍亚洲精品99久久精品| 亚洲国产成人午夜在线一区 | 亚洲男女毛片无遮挡| 亚洲毛片在线观看| 久久久久99精品国产片| 亚洲在线一区| 欧美另类69精品久久久久9999| 久久久噜噜噜久噜久久 | 亚洲一区二区在| 日韩视频精品在线| 久久久久久久久久久成人| 欧美一区二区三区视频在线| 欧美日韩视频| 欧美黄色成人网| 在线观看亚洲视频啊啊啊啊| 午夜亚洲福利| 午夜精品久久久久久久久久久| 欧美日韩国产a| 亚洲第一中文字幕| 在线色欧美三级视频| 久久成人免费| 久久久久久色| 狠狠色狠狠色综合系列| 性欧美大战久久久久久久免费观看 | 久久伊人精品天天| 狂野欧美激情性xxxx欧美| 国产一区三区三区| 欧美在线日韩| 免费久久99精品国产自在现线| 国产有码在线一区二区视频| 欧美一区二区三区免费在线看| 欧美一级淫片aaaaaaa视频| 国产伦精品一区二区三区免费迷| 亚洲天堂成人在线视频| 亚洲欧美日韩国产一区| 国产精品国产三级国产普通话蜜臀| 亚洲乱亚洲高清| 亚洲一区二区综合| 国产麻豆精品视频| 久久久之久亚州精品露出| 免费成人你懂的| 91久久国产综合久久蜜月精品| 欧美国产日本韩| 一本大道久久a久久精二百| 亚洲欧美日韩成人| 国内免费精品永久在线视频| 葵司免费一区二区三区四区五区| 欧美风情在线观看| 一本一本久久| 国产精品一区毛片| 久久一本综合频道| 日韩一级在线| 久久久久久亚洲精品中文字幕 | 欧美体内she精视频| 亚洲欧美激情一区二区| 免费中文字幕日韩欧美| 亚洲乱码日产精品bd| 国产精品欧美久久| 久久久亚洲国产美女国产盗摄| 最新日韩在线视频| 久久爱www久久做| 在线免费精品视频| 欧美日韩在线一区二区| 小嫩嫩精品导航| 亚洲国产美女| 久久激情中文| 一区二区三区日韩精品| 韩日精品视频| 国产精品草草| 欧美成人国产| 欧美一二三区在线观看| 91久久综合| 久久青青草综合| 亚洲性色视频| 亚洲精品国产欧美| 国产一区二区日韩精品| 欧美日韩中文字幕在线视频| 久久精品av麻豆的观看方式| 中国成人黄色视屏| 亚洲第一综合天堂另类专| 久久国产日本精品| 亚洲一区二区精品在线观看| 亚洲高清在线观看一区| 国产精品久久久久7777婷婷| 欧美成年人视频网站| 久久全国免费视频| 新67194成人永久网站| 一区二区激情| 日韩一级免费观看| 亚洲国产精品激情在线观看| 久久久综合精品| 欧美资源在线| 午夜精品偷拍| 亚洲亚洲精品在线观看| 一本色道久久综合亚洲精品小说| 在线精品视频一区二区三四| 国产日韩一区二区三区| 国产精品亚洲欧美| 国产精品亚洲一区| 国产精品普通话对白| 国产精品极品美女粉嫩高清在线| 欧美精品成人在线| 欧美理论片在线观看| 欧美黑人多人双交| 欧美另类亚洲| 欧美日韩不卡一区| 欧美日韩精品免费看| 欧美日韩第一页| 欧美视频一区二区三区在线观看| 欧美伦理a级免费电影| 欧美日韩高清在线一区| 欧美日韩亚洲91| 欧美性猛交xxxx免费看久久久| 欧美午夜www高清视频| 欧美新色视频| 国产欧美亚洲日本| 狠狠综合久久av一区二区小说| 好看的av在线不卡观看| 亚洲高清资源| 一区二区黄色| 性欧美精品高清| 久久免费视频观看| 欧美激情一区二区三区蜜桃视频| 91久久精品日日躁夜夜躁欧美| 亚洲肉体裸体xxxx137| 一本色道久久88精品综合| 亚洲一区二区三| 久久美女艺术照精彩视频福利播放| 麻豆国产精品va在线观看不卡| 欧美精品久久99| 国产精品日韩在线播放| 国语精品一区| 99国产精品久久久久久久| 欧美一区精品| 欧美激情精品久久久| 亚洲系列中文字幕| 久久午夜电影网| 欧美午夜激情在线| 黄色成人av在线| 中文有码久久| 久久亚洲综合色| 在线亚洲自拍| 久久综合久久综合久久综合| 欧美日韩一区二区在线播放| 国产在线视频不卡二| 妖精成人www高清在线观看| 久久精品盗摄| av成人黄色| 久久一区二区三区国产精品 | 欧美激情影院| 国产偷自视频区视频一区二区| 亚洲精品一区二区三区99| 午夜精品福利电影| 亚洲精品国精品久久99热| 欧美一区二区三区久久精品茉莉花| 欧美乱妇高清无乱码| 伊人久久综合97精品|