How to get the GIT in Delphi 7?

后端 未结 3 434
忘掉有多难
忘掉有多难 2021-01-19 17:15

I\'m trying to get the Global Interface Table by using the following code (Delphi):

uses Comobj, ActiveX;

var
   cGIT : IGlobalInterfaceTable = NIL;
const
          


        
相关标签:
3条回答
  • 2021-01-19 17:49

    Here's my unit that does it. I put this together when I was compiling in D2006, but I don't see why it would be any different in D7. I use it for storing an interface to a DCOM server and sharing it between multiple threads.

    unit GlobalInterfaceTable;
    
    interface
    
    uses Types,
         ActiveX;
    
    type
      IGlobalInterfaceTable = interface(IUnknown)  
         ['{00000146-0000-0000-C000-000000000046}']  
         function RegisterInterfaceInGlobal (pUnk : IUnknown; const riid: TIID; out dwCookie : DWORD): HResult; stdcall;  
         function RevokeInterfaceFromGlobal (dwCookie: DWORD): HResult; stdcall;  
         function GetInterfaceFromGlobal (dwCookie: DWORD; const riid: TIID; out ppv): HResult; stdcall;  
       end;
    
      function GIT: IGlobalInterfaceTable;
    
    implementation
    
    uses ComObj;
    
    const
      CLSID_StdGlobalInterfaceTable : TGUID = '{00000323-0000-0000-C000-000000000046}';
    
    function GIT: IGlobalInterfaceTable;  
    begin  
      // This function call always returns the singleton instance of the GIT  
      OleCheck(CoCreateInstance (CLSID_StdGlobalInterfaceTable, NIL, CLSCTX_ALL, IGlobalInterfaceTable, Result));  
    end;
    
    end.
    
    0 讨论(0)
  • 2021-01-19 17:53

    You have defined CLSID_StdGlobalInterfaceTable incorrectly: you have supplied the GUID of the interface rather than a concrete class.

    I don't have the Windows header files around, so I can't check against them, but a search suggests it should be:

     CLSID_StdGlobalInterfaceTable: TGUID = '{00000323-0000-0000-C000-000000000046}';
    
    0 讨论(0)
  • 2021-01-19 18:00

    Have you used OleView32 to verify the GUID of the class? That utility is available in the Windows SDK and allows you to walk the registry of interfaces much easier than regedit. I would classify the utility as a must have for any COM development.

    0 讨论(0)
提交回复
热议问题