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

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  回復(fù)  更多評論   

# 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。

  回復(fù)  更多評論   

# 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 );
}
}
  回復(fù)  更多評論   

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

3 使用 CLR hosting  回復(fù)  更多評論   

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

4 修改clr編譯選項  回復(fù)  更多評論   

公告

EMail:itech001#126.com

導(dǎo)航

統(tǒng)計

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

常用鏈接

隨筆分類

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1815011
  • 排名 - 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>
              在线日韩电影| 亚洲小说欧美另类婷婷| 永久555www成人免费| 国产精品二区影院| 亚洲美女视频网| 老色鬼精品视频在线观看播放| 羞羞色国产精品| 久久狠狠婷婷| 久久久噜噜噜久久人人看| 久久精品免费| 久久综合网络一区二区| 欧美成人一区二区三区在线观看| 欧美成va人片在线观看| 欧美日产一区二区三区在线观看| 国产精品草莓在线免费观看| 国产精品亚洲综合色区韩国| 狠狠色狠色综合曰曰| 亚洲破处大片| 久久久久88色偷偷免费| 久久久噜噜噜久久久| 欧美日韩免费在线| 国产欧美日韩一区二区三区| 亚洲国产精品一区制服丝袜 | 国产精品久久久久av免费| 国产日产高清欧美一区二区三区| …久久精品99久久香蕉国产| 亚洲自拍高清| 欧美成人嫩草网站| 亚洲午夜精品久久久久久app| 久久人人爽爽爽人久久久| 欧美亚日韩国产aⅴ精品中极品| 狠狠色噜噜狠狠色综合久| 亚洲一区二区精品在线| 欧美国产一区二区| 性欧美激情精品| 欧美视频在线观看| 亚洲老板91色精品久久| 久久蜜桃精品| 亚洲视频一二三| 欧美激情一区在线| 在线观看视频一区二区欧美日韩| 香蕉免费一区二区三区在线观看| 亚洲国产成人av在线| 亚洲一区自拍| 欧美日韩免费观看一区| 亚洲人被黑人高潮完整版| 国产日韩专区| 亚洲精品在线看| 免费在线成人av| 欧美一级理论片| 国产精品无码永久免费888| 一本色道久久综合亚洲精品不 | 在线视频欧美精品| 欧美精品色综合| 亚洲国产欧美在线人成| 麻豆成人小视频| 国产精品永久入口久久久| 欧美三级乱码| 另类专区欧美制服同性| 国产亚洲欧美一区| 欧美一级片久久久久久久| 亚洲美女在线看| 欧美日韩mp4| 99视频精品全部免费在线| 亚洲电影在线播放| 欧美 日韩 国产精品免费观看| 亚洲大胆av| 亚洲国产mv| 欧美精品在欧美一区二区少妇| 亚洲黄页视频免费观看| 免费成人av| 欧美成年人视频| 日韩视频精品| aa国产精品| 国产精品亚洲综合天堂夜夜| 欧美一区影院| 欧美在线资源| 亚洲国产免费| 日韩网站在线观看| 国产精品黄色在线观看| 欧美亚洲综合另类| 久久久久久国产精品mv| 亚洲激情网站免费观看| 亚洲精品视频在线| 国产精品久久久久久久久久三级 | 亚洲日本在线观看| 日韩午夜激情av| 国产麻豆日韩欧美久久| 美日韩精品免费观看视频| 欧美国产大片| 香蕉av777xxx色综合一区| 久久精品国产亚洲aⅴ| 亚洲激情视频在线观看| 一区二区免费看| 精品盗摄一区二区三区| 亚洲精品看片| 国产亚洲在线| 国产精品网站在线观看| 欧美1区3d| 国产精品久久久久aaaa| 另类酷文…触手系列精品集v1小说| 美女精品网站| 欧美一区二区三区另类| 久久久久久久久综合| 在线视频精品一| 久久精品观看| 亚洲一区二区av电影| 开元免费观看欧美电视剧网站| 亚洲资源av| 你懂的国产精品永久在线| 亚洲欧美日韩一区二区三区在线观看 | 久久综合久久久久88| 亚洲伊人伊色伊影伊综合网 | 国产精品videosex极品| 免费不卡欧美自拍视频| 欧美日韩中文字幕在线| 亚洲在线观看视频| 欧美xx视频| 女人天堂亚洲aⅴ在线观看| 国产精品―色哟哟| 日韩视频中文| 亚洲精品影院| 免费成人高清| 久久亚洲春色中文字幕久久久| 欧美性大战久久久久| 亚洲激情二区| 亚洲精品欧美专区| 久久这里有精品视频| 亚洲婷婷综合久久一本伊一区| 久久综合九色| 久久精品91| 国产精品一区二区三区久久久| 日韩视频―中文字幕| 99热在这里有精品免费| 欧美肥婆bbw| 欧美激情偷拍| 一区二区欧美国产| 夜夜嗨一区二区三区| 欧美精品综合| 亚洲片国产一区一级在线观看| 最新中文字幕一区二区三区| 久久天堂av综合合色| 久久综合图片| 亚洲高清精品中出| 欧美成人精品1314www| 亚洲高清视频在线观看| 亚洲欧洲日本一区二区三区| 欧美大胆a视频| 日韩一级免费| 午夜日韩福利| 狠狠色2019综合网| 麻豆久久精品| 亚洲精品四区| 亚洲欧美日本国产有色| 国产精品一区二区视频| 午夜精品视频在线观看| 久久亚洲不卡| 亚洲精品偷拍| 国产精品激情av在线播放| 亚洲欧美日韩区| 欧美a级一区| 亚洲深夜激情| 国产主播一区二区三区四区| 狼人社综合社区| 亚洲美女一区| 久久精品盗摄| 亚洲精品老司机| 国产精品一区二区你懂的| 久久米奇亚洲| 中文在线资源观看网站视频免费不卡| 欧美在线一二三四区| 亚洲黄色一区| 国产精品日韩一区二区| 久久性色av| 制服诱惑一区二区| 久久精品视频免费播放| 亚洲欧美综合另类中字| 国产一区清纯| 欧美日韩久久| 久久久久久久久久久一区| 夜夜夜精品看看| 久久综合久久综合久久综合| 9久草视频在线视频精品| 亚洲欧美日韩天堂| 亚洲电影观看| 国产麻豆一精品一av一免费| 欧美成人自拍| 日韩小视频在线观看| 国产精品老女人精品视频| 看片网站欧美日韩| 亚洲欧美日韩综合| 夜夜嗨一区二区| 欧美激情一区二区三区在线视频 | 老巨人导航500精品| 亚洲一区二区三区在线看| 亚洲国产欧美一区二区三区久久| 久久久久久69| 欧美一区二区三区在线观看| 夜夜嗨av一区二区三区中文字幕| 亚洲大片一区二区三区|