如何獲得COM的Interop互動庫C#原始碼

鷓鴣菜發表於2015-01-09

如何獲得COM的Interop互動庫的原始碼

 

How can I generate C# source code for a COM Interoplibrary instead of an assembly?

Whenimporting a COM library (either directly with tlbimp, or indirectly with visualstudio add reference dialog,) is there a way to generate C# source code insteadof a binary interop assembly, like Interop.Word.dll, for example?

UPD:Reflector is bad idea. Problem is that for the com interface is not only asignature, but the order of the members. Reflector this order is violated

在匯入一個COM(tlbimp直接或間接與visual studio新增引用對話方塊中,)有辦法生成c#原始碼,而不是二進位制互操作組裝,Interop.Word。例如,dll?

更新:反射器是壞主意。問題是,com介面不僅是一個簽名,但成員的順序。反射器這是違反規則。

I would go aheadand generate the interop assembly using TLBIMP, and the use Reflector to disassemble it. The interop assembly has noactual implementation code, as you will see. You can then just copy and pastethe code (or the CoClasses and interfaces you need) into a new .cs file in yourproject.

我會繼續使用TLBIMP生成互動操作組裝,拆卸和使用反射器。互操作組裝沒有實際實現的程式碼,您將看到。你可以複製和貼上的程式碼(或者你需要的輔助類和介面)到一個新的。cs檔案在您的專案。

Youcannot generate C# directly, but if your real problem is that you have a needto tweak the interop library then you might have better luck using the CLRInterop team's custom TLBIMP tool on codeplex - it's pretty flexible and youhave full source [to it.]

http://clrinterop.codeplex.com/releases/view/17579

Update:If you're really trying avoid shipping binaries, then you could feasiblyintegrate the above tool (in source format) into your project so that yougenerate this interop library at runtime. Result? No binaries toship.

你不能直接生成c#,但如果你的真正的問題是,你需要調整互動操作庫,那麼你可能會有更好的運氣使用CLR互操作團隊的定義TLBIMP工具在codeplex——很靈活,你有完整的原始碼()
http://clrinterop.codeplex.com/releases/view/17579
更新:如果你真的想避免航運二進位制檔案,然後你能輕鬆將上面的工具(在源格式)整合到你的專案,這樣你生成這個互操作在執行時庫。結果呢?船沒有二進位制檔案。

In general it cannot be done. C# does notsupport all possible constructs needed to create a working interop assembly.You cannot add e.g. attributes to return types or method parameters in C#although they are needed sometimes to help the marshaller to correctlytranslate some C++ types.

 

Yours, Alois Kruas

一般情況下它不能被完成。c#不支援所有可能的結構需要建立一個工作互操作程式集。你不能新增如屬性返回型別或方法引數在c#中雖然他們有時需要幫助marshaller正確翻譯一些c++型別。

你的,阿洛伊斯Kruas

How do I generate COM interop proxies into C# source code?

我如何生成COM互操作代理到c#原始碼嗎?

Take a look at the following MSDN article:
How to: Create Wrappers Manually (Talks about how to createyour interop assembly manually.)

http://msdn.microsoft.com/en-us/library/x8fbsf00.aspx


Once you've got the interop assembly, use a toollike Reflector to disassemble it and generate the raw C#source. Reflector.FileDisassembler makes this really easy.

http://www.denisbauer.com/NETTools/FileDisassembler.aspx


Now you can include the generated C#/VB sources directly into yourassembly.

看看下面的MSDN文章:
如何:建立包裝器手動(討論如何建立你的互操作手動裝配。)
一旦你得到了互操作組裝,使用反射器等工具拆卸並生成原始c#源。反射器。FileDisassembler使這一切變得簡單。
現在你可以包括生成c# / VB來源直接進入您的程式集。

I do not know simplerway, and extract interface descriptions via Reflector. However in VS 2010Microsoft will do this for you automatically.

我不知道更簡單的方式,通過反射器和提取介面描述。然而在VS 2010微軟將自動為您做到這一點。

 

反編譯工具Reflector下載(整合FileGeneratorFileDisassembler)


Reflector是一款比較強大的反編譯工具,相信很多朋友都用過它,但reflector本身有很多侷限性,比如只能一個一個的檢視方法等,但幸好reflector支援外掛功能目前網上有很多reflector的外掛,本人找取了兩個應用範圍很廣,並且廣受好評的外掛:Reflector.FileDisassembler和Reflector.FileGenerator和Reflector進行了整合,放在了一個壓縮包中,大家可以直接解壓縮後就開始使用,其中FileGenerator在網上沒有現成dll,本人編譯後將其取出,放在了壓縮包中,一直在苦苦找尋的朋友這次可以拿來直接用了:)

點選下載Reflector整合壓縮包

本壓縮包中Reflector.exe已經升級為最新的5.0版本,具體的使用方法不多說了,只簡單介紹一下本壓縮包的使用步驟:
先下載本壓縮包並解壓縮,執行其中的Reflector.exe(主程式),初次執行會彈出錯誤提示對話方塊,因為引用的兩個外掛DLL是按照我本地實際情況配置的,所以你還需要根據你的實際情況來從新配置一下,方法很簡單,我們拿引用FileGenerator.dll來做一個範例,
首先介紹一下Filegenerator,FileGenerator外掛的作用是:根據dll檔案,把裡面的原始檔匯出成檔案,匯出來的檔案除了沒有註釋,變數名也變了,其它的可謂是沒有差別。對於一些比較好的控制元件,如果不是開源的,完全可以匯出成檔案,然後自己加上註釋,少許修改,很好的利用起來。(不開源的dll,用起來也不放心啊)
具體的初始化設定方法:點選View->Add-Ins...,彈出一個視窗,然後點選Add->選擇資料夾裡面的:"FileGenerator.dll",點選close.
然後回到Reflector視窗,Tool->Generator File(s)... 右邊就出現了外掛的視窗,選中左邊的dll檔案,點選右邊的匯出檔案,原始碼就全部匯出來了!
另一個外掛Reflector.FileDisassembler.dll設定方法也和這個一樣。

另外再提供一些Reflector的相關外掛下載:

Reflector.FileDisassembler
This add-in can be used to dump the disassembler output to files for any Reflector supported language.
Website Download   

Reflector.CodeMetrics 
Analyses .NET assemblies and shows design quality metrics. The menu item is registered under the "Tools" menu.
Website Download   

Reflector.SQL2005Browser
This add-in allows to browse .NET assemblies stored in SQL Server 2005 (Yukon) databases. 
Website Download   

Reflector.DelphiLanguage 
The Delphi view that is used inside .NET Reflector provided as a language add-in. 
Website Download   

Reflector.McppLanguage 
This add-in extends Reflector with a Managed C++ language rendering module. 
Website Download   

Reflector.ChromeLanguage 
This add-in extends Reflector with a Chrome language rendering module. 
Website Download   

Reflector.Diff 
This add-in shows differences between two versions of the same assembly. 
Website Download   

Reflector.VisualStudio 
This program is hosting .NET Reflector inside the Visual Studio 2003 IDE. Run Reflector.VisualStudio.exe to register the add-in with Visual Studio. 
Website Download   

Reflector.ClassView 
Shows class definitions as plain text with color coding. The menu item is registered under the "Tools" menu. 
Website Download   

Reflector.CodeModelView 
This add-in shows the underlying code model objects for a selected node in .NET Reflector. The menu item is registered under the "Tools" menu. 
Website Download   

Reflector.FileGenerator 
This add-in can be used to dump the disassembler output to files for any Reflector supported language. 
Download   

Reflector.Graph 
This add-in draws assembly dependency graphs and IL graphs. 
Website Download   

Reflector.OpenRunningAssembly 
Opens an assembly or dependency from a process running on the system. The menu item is registered under the "Tools" menu. 
Website Download



來源:http://daiwen.blog.ccidnet.com/blog-htm-do-showone-uid-55708-type-blog-itemid-194608.html

作者: XuGang   網名:鋼鋼

出處: http://xugang.cnblogs.com

宣告: 本文版權歸作者和部落格園共有。轉載時必須保留此段宣告,且在文章頁面明顯位置給出原文連線地址!

Takea look at the following MSDN article:

·        How to: Create WrappersManually (Talks abouthow to create your interop assembly manually.)

Once you've got the interop assembly, use a tool like Reflector to disassemble it and generate the rawC# source. Reflector.FileDisassembler makesthis really easy.

Now you caninclude the generated C#/VB sources directly into your assembly.

 

http://blog.csdn.net/nuaalfm/article/details/2089149

FileDisassembler是Reflector 的一個外掛,老外做的東西還真好用

.NET Reflector 下載地址(現在的最新版本是5.0.50.0)

http://www.aisto.com/roeder/dotnet
或者
http://www.aisto.com/roeder/dotnet/Download.aspx?File=Reflector

FileDisassembler 下載地址

http://www.denisbauer.com/Downloads/Reflector.FileDisassembler.zip

或者從以下地址下載

http://dl2.csdn.net/down4/20080111/11113854907.rar

使用方法

開啟 Reflector ,在 view選單下的 Add-Ins,將 Reflector.FileDisassembler.dll 新增到裡面。然後載入一個需要反編譯的dll檔案,選中,然後選擇 Tools-File Disassembler 開啟右側 File Disassembler 視窗,點選 Generate 按鈕就ok啦。

我試了一下,還真是不錯,連工程檔案都生成了!
 

特別說明:

NET Reflector是是收費的,但是外掛是開源的,下載地址為:http://reflectoraddins.codeplex.com/


相關文章