5

照会する特定の/カスタム インターフェイスを備えたいくつかの directshow フィルター (COM) を含む .dll があります。

ほとんどのサード パーティの directshow コンポーネントには、クロス環境通信 (C# typelib インポート) に使用できる埋め込み .tlb ファイルが含まれています。

idl/tlb ファイルが提供されていないため、c# に必要なインターフェイスを手動で作成する必要はありません。

COM .dll から tlb (または、少なくとも MIDL でコンパイルできる idl) を生成することは可能ですか?

4

1 に答える 1

6

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;
}

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

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

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

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.

Kind regards,

Lord BattenBerg

于 2014-01-13T21:29:59.817 に答える