Search code examples
c++comvisual-studio-2005

Class not registered


I'm working through "Developer's Workshop to COM and ATL 3.0" by Andrew W. Troelsen.

I'm trying to implement the lab in Chapter 3.

It shows you how to build a COM client to connect to an inprocess COM server that was developed in an earlier lab.

When I run the client, I receive the error "Class not registered" when calling 'CoGetClassObject'.

Here is a snippet of code:

// Get the class factory pointer of CoCar.
hr = CoGetClassObject(CLSID_CoCar, CLSCTX_INPROC_SERVER, NULL, IID_IClassFactory, (void**)&pCF);

if(SUCCEEDED(hr))
{
    // Make a CoCar & get ICreateCar
    hr = pCF->CreateInstance(NULL, IID_ICreateCar, (void**)&pICreateCar);
    pCF->Release();
}
else
{
    char buff[100];
    BOOL bRet = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, hr, 0, buff, sizeof(buff), 0);
    std::cout << buff << std::endl;
}

I have tried to register the class by merging the following .reg file with the system registry:

REGEDIT
HKEY_CLASSES_ROOT\CarInProcServer.CoCar\CLSID = {EFC76CF8-71B8-477b-890A-1233BD9177CB}
HKEY_CLASSES_ROOT\CLSID\{EFC76CF8-71B8-477b-890A-1233BD9177CB} = CarInProcServer.CoCar
HKEY_CLASSES_ROOT\CLSID\{EFC76CF8-71B8-477b-890A-1233BD9177CB}
\InprocServer32 = C:\Users\Steven\Documents\Visual Studio 2005\Projects\CarInProcServer\release\CarInProcServer.dll

Not sure if this is relevant, but here is my .def file:

LIBRARY "CarInProcServer"
EXPORTS
DllGetClassObject   @1  PRIVATE
DllCanUnloadNow     @2  PRIVATE

NB: I'm using Windows 7

Can anyone help?

Thanks


Got it!

I manually added:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Classes\CLSID{EFC76CF8-71B8-477b-890A-1233BD9177CB} \InprocServer32 = "C:\Users\Steven\Documents\Visual Studio 2005\Projects\CarInProcServer\release\CarInProcServer.dll"

to the registry.

It seems merging the .reg file with this entry in it did not work. Thanks to Ken White for his help. (and others who suggested solutions)


Solution

  • Open a command prompt, change to your DLL's folder, and run regsvr32.exe:

    cd \Users\Steven\Documents\Visual Studio 2005\Projects\CarInProcServer\release 
    regsvr32 CarInProcServer.dll