如何获得COM的Interop交互库C#源代码

如何获得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/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值