Simplifying Interface and Type Library Registration

 < Free Open Study > 



Rather than writing a massive REG file that enters all interface and type information into the system registry, you will find it far simpler to make use of a COM library function that does so automatically. The LoadTypeLibEx() function is equipped to load up a type library and provide access to its contents programmatically using an ITypeLib pointer. When calling LoadTypeLibEx(), you send in the REGKIND_REGISTER flag to request automatic registration of your interfaces and type library. Obvious places to call this COM library function would be in DllRegisterServer(), or from within a WinMain() implementation. LoadTypeLibEx() takes a total of three parameters:

// LoadTypeLibEx() allows you to programmatically register the interfaces defined in // your server's type library, as well as the library itself. LoadTypeLibEx(LPOLESTR szFile,         // Name of TLB file.             REGKIND regKind,           // REGKING flag.             ITypeLib** ppTlib);        // [out] parameter.

The REGKIND flag must be set to REGKIND_REGISTER to force the necessary information to be placed into the system registry. The following code loads up the shapes.tlb type library, and programmatically registers the interfaces and type library into the registry:

// Automatically register your type and interface information as so... ITypeLib* pTLib = NULL; LoadTypeLibEx(L"Shapes.tlb", REGKIND_REGISTER, &pTLib); pTLib->Release();

Notice that we must send in an ITypeLib pointer to LoadTypeLibEx(), even though we have no intention of using it. This pointer has been AddRef-ed, and therefore we must release it. With these three little lines of code, you receive the following registry entries automatically (assuming your interfaces have been tagged with the [oleautomation] attribute):

  • HCKR\TypeLib\{your LIBID}\1.0

  • HCKR\TypeLib\{your LIBID}\1.0\0\win32 = <path to your *.tlb file>

  • HCKR\TypeLib\{your LIBID}\Flags

  • HCKR\TypeLib\{your LIBID}\1.0\Helpdir

  • HKCR\Interface\{your IID}

  • HKCR\Interface\ProxyStubClsid = <CLSID of oleaut32.dll>

  • HKCR\Interface\ProxyStubClsid32 = <CLSID of oleaut32.dll>

  • HKCR\Interface\TypeLib = <LIBID of *.tlb file describing the interfaces>

If you configured your interfaces with the [oleautomation] attribute, the ProxyStubClsid32 subkey points to the universal marshaler. Nice, huh? Once the correct registry information is entered into the system, you can now safely cross process boundaries using oleaut32.dll (a.k.a. {00020424-0000-0000-C000-000000000046}).



 < Free Open Study > 



Developer's Workshop to COM and ATL 3.0
Developers Workshop to COM and ATL 3.0
ISBN: 1556227043
EAN: 2147483647
Year: 2000
Pages: 171

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net