Class not registered

2019-03-01 20:26发布

问题:

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)

回答1:

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


回答2:

Did you try registering the COM server with regsvr32.exe?



回答3:

Is the value of CLSID_CoCar equal to the value in your reg file? ({EFC76CF8-71B8-477b-890A-1233BD9177CB}), or have they been regenerated to different values?

If so, have you checked that these values have been correctly merged into your registry?

Have you called CoInitialize?