当没有提供时,从COM + dll获取IDL(用于TLB) [英] Getting IDL (for TLB) from a COM+ dll when it is not provided
问题描述
我有一个.dll包含一些directshow过滤器(COM)与特定/自定义接口来查询。
I have a .dll that contains some directshow filters (COM) with specific/custom interfaces to query.
大多数第三方directshow组件包含嵌入的.tlb文件可以用于跨环通信(C#typelib import)。
Most 3rd party directshow components contain embedded .tlb files that can be used for cross-enviroment communication (C# typelib import).
我不愿意尝试手动创建c#所需的接口,因为没有提供idl / tlb文件。
I would hate to have to attempt to manually create the interfaces needed for c# because no idl/tlb files were provided.
是否可以从COM .dll生成tlb(或至少是一个idl,我可以MIDL编译)?
Is it possible to generate a tlb (or at least, an idl, which I can MIDL compile) from a COM .dll?
推荐答案
是的,可以反向工程/反汇编IDL(或其他非常接近它)。你需要做的是给自己一个新的C ++控制台项目,它提供默认代码
Yes, it is possible to reverse engineer/disassemble IDL (or something very close to it). What you need to do is give yourself a new C++ Console Project which gives the default code of
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
,然后在#include语句下插入#import语句。所以我一直在玩C#汇编标记为COM Interop DLL,我称之为ComExample2,它住在与我添加的C ++控制台项目相同的解决方案,这意味着我可以使用一个很好的相对路径名。所以我的#import语句看起来像
and then you insert an #import statement underneath the #include statement. So I have been playing with C# assembly marked up to function as a COM Interop DLL and I have called it ComExample2 and it lives in the same solution as the C++ console project that I added which means I can use a nice relative pathname. So my #import statement looks like
#import "..\ComExample2\bin\Debug\ComExample2.tlb" no_namespace named_guids
然后构建控制台应用程序。如果你深入研究在生成期间生成的文件,你会发现一个以.TLH结尾的文件,它代表类型库头。所以我的路径是
Then you build your console application. If you delve into the files generated during the build you will find a file that ends with .TLH which stands for type library header. So my path is
..\ComExample2\ConsoleApplication1\Debug\comexample2.tlh
在我的文件里面看起来很像idl。这是一个编辑片段,给你一个风味....
Inside my file is something which looks very much like idl. Here is an edited snippet to give you a flavour....
struct __declspec(uuid("515b1b18-1602-4d42-b743-f1b3c458a0d0"))
/* LIBID */ __ComExample2;
struct /* coclass */ ComExampleClass2;
//
// Type library items
//
struct __declspec(uuid("713007fe-e74c-4fec-b91a-5ef8df279929"))
IFoo : IDispatch
{
//
// Wrapper methods for error-handling
//
_bstr_t Greeting ( );
long Sim (
long a,
long b );
//
// Raw methods provided by interface
//
virtual HRESULT __stdcall raw_Greeting (
/*[out,retval]*/ BSTR * pRetVal ) = 0;
virtual HRESULT __stdcall raw_Sim (
/*[in]*/ long a,
/*[in]*/ long b,
/*[out,retval]*/ long * pRetVal ) = 0;
};
struct __declspec(uuid("efe233b5-8ab3-4414-855e-1f027e0a72d5"))
ComExampleClass2;
// interface _Object
// [ default ] interface IFoo
这是生成代码,以便您可以轻松地将C ++代码对照COM库。
All of this is generated code so that you can script C++ code against a COM library easily. You'll have to pick through what you need but hopefully that should be enough.
亲爱的,
Lord BattenBerg
Lord BattenBerg
这篇关于当没有提供时,从COM + dll获取IDL(用于TLB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!