COM registration & MIDL issues RRS feed

  • Question

  • Hello,


    I'm trying to use an existing IDL file and create a COM server using the provided interfaces.  I have been able to create a project, compile the IDL using Visual Studio's built-in MIDL compiler, and create a class inheriting the interface, with functionality.  This project successfully compiles as a DLL.

    When I attempt to use my COM server in another application (I #define DLLPATH to the path of my DLL):


    #import DLLPATH named_guids
    HRESULT hr = CoCreateInstance(....); // instance created using the CLSCTX_INPROC_SERVER flag


    My application compiles, but my interface pointer is NULL and I receive the following HRESULT:


    Classfactory cannot supply requested class.

    I'm assuming this is a result of my COM DLL being improperly registered via regsvr32; however, I have attempted registering my DLL with regsvr32 on every build, and each register is successful.  I have been reading as much support as I can (with very little documentation on MIDL and COM I might add) and the MIDL compiler flag REGISTER_PROXY_DLL should define DllEntryPoint, DllRegisterServer, and DllUnregisterServer for me, but it does not.  MIDL ONLY generates DllGetClassObject and DllCanUnloadNow.  I have not been able to figure out how to tell MIDL via Visual Studio to either auto-generate DllEntryPoint, DllRegisterServer, and DllUnregisterServer, or to tell MIDL NOT to auto-generate DllGetClassObject and DllCanUnloadNow.

    I have attempted manually entering registry keys into the HKEY_CLASSES_ROOT\CLSID, HKEY_CLASSES_ROOT\Interfaces, and HKEY_CLASSES_ROOT\AppID keys, but nothing has worked and I can find no documentation on the precise setup of COM registry keys.

    Monday, February 7, 2011 10:58 PM


  • It's your own COM server that must implement DllRegisterServer, not the MIDL compiler. Assuming that the interfaces are automation-compliant there is no need to create a proxy-stub.

    Typically one uses either ATL or MFC as the framework for building COM servers. You really shouldn't be trying to do it from scratch without a deep understand of how COM works, and frankly, it's not a good use of your time. Both will automatically generate the DllRegisterServer code for you.

    Assuming that your understanding of COM is rudimentary, I strongly suggest you invest in a COM book. Personally I prefer to use ATL, so I would recommend ATL Internals by Rector and Sells, or Profesional ATL COM Programming by Grimes.

    • Marked as answer by Jesse Jiang Monday, February 14, 2011 2:45 AM
    Tuesday, February 8, 2011 12:24 AM