ATL COM class registration .rgs file defaults

Jack Smith picture Jack Smith · Apr 20, 2011 · Viewed 9.3k times · Source

I'm creating a COM server executable, and have run into a problem with class registration. When I created my class object, the automatically generated .rgs file looked like this:

HKCR
{
    NoRemove CLSID
    {
        ForceRemove {4C6DAD45-64B4-4C55-81C6-4CE125226421} = s 'Test Class'
        {
            ForceRemove Programmable
            LocalServer32 = s '%MODULE%'
            {
                val ServerExecutable = s '%MODULE_RAW%'
            }
            TypeLib = s '{EAA173CA-BDBC-463A-8B7A-B010EFA467BC}'
            Version = s '1.0'
        }
    }
}

This created the registry entries correctly for the CLSID. However, when attempting to call CoCreateInstance externally, I was experiencing a hang.

hr = CoCreateInstance( __uuidof(Test), NULL, CLSCTX_ALL, __uuidof(ITest), (void**)&pTest);

After looking at a few other projects for examples, I noticed that they all had registry entries of the type:

HKEY_CLASSES_ROOT\<MODULE>.<CLASS>
HKEY_CLASSES_ROOT\<MODULE>.<CLASS>\CLSID

I investigated the .rgs files for these classes, and noticed they had extra entries not present in my .rgs file. I added them to mine, changing it to:

HKCR
{
    TestModule.Test = s 'Test Class'
    {
        CLSID = s '{4C6DAD45-64B4-4C55-81C6-4CE125226421}'
    }

    NoRemove CLSID
    {
        ForceRemove {4C6DAD45-64B4-4C55-81C6-4CE125226421} = s 'Test Class'
        {
            ForceRemove Programmable
            LocalServer32 = s '%MODULE%'
            {
                val ServerExecutable = s '%MODULE_RAW%'
            }
            TypeLib = s '{EAA173CA-BDBC-463A-8B7A-B010EFA467BC}'
            Version = s '1.0'
        }
    }
}

And lo and behold, my CoCreateInstance call no longer hung, and I was able to properly retrieve a pointer to an ITest interface.

Now, my question is, with the above particulars in mind, how can I ensure that any future classes I create have this correct .rgs file format? Is there some option I'm missing when creating the class objects? Or will I need to manually add the above for every class I create?

I'm using Visual Studio 2010.

Answer

Hans Passant picture Hans Passant · Apr 20, 2011

That's the ProgID for the coclass. It is primarily used by scripting languages, the ones that use late binding. CreateObject() is the usual function name. That this has anything to do with a hang is unexplainable, you'd better debug it.

The .rgs entry is otherwise automatically generated by the ATL wizard. The ProgID edit box is the lower right one. It doesn't get filled in automatically like the rest of them, you probably missed it.