visual-c++comatl

How to programmatically update .rgs files to reflect changes made in IDL files?


Is there any tool to update .rgs files to reflect change made in the IDL ?

rgs files are created by the ATL control wizzard but I can't find a way to refresh thoses files.

When we change the uuid of an interface (within the .IDL file), we are forced to changed by hand the "hard copy" values in those .rgs files. This is quiet prone to error.

I found this interesting project that intend to fill this gap but, accordingly the last comments, it didn't works any more since VC2005.


Solution

  • ATL CAtlModule implementation offers virtual CAtlModule::AddCommonRGSReplacements which you can override and add substitutions to remove hardcoded RGS values.

    For example, my typical ATL code looks like this:

    class CFooModule : 
        public CAtlDllModuleT<CFooModule>
    {
    [...]
    
    // CAtlModule
        HRESULT AddCommonRGSReplacements(IRegistrarBase* pRegistrar)
        {
            // Error handling omitted for code brevity
            __super::AddCommonRGSReplacements(pRegistrar);
            ATLASSERT(m_libid != GUID_NULL);
            pRegistrar->AddReplacement(L"LIBID", _PersistHelper::StringFromIdentifier(m_libid));
            pRegistrar->AddReplacement(L"FILENAME", CStringW(PathFindFileName(GetModulePath())));
            pRegistrar->AddReplacement(L"DESCRIPTION", CStringW(AtlLoadString(IDS_PROJNAME)));
            return S_OK;
        }
    

    In COM classes I override UpdateRegistry method to add tokens with third parameter of standard call _pAtlModule->UpdateRegistryFromResource.

    As a result, many .RGS are shared between COM classes because hardcoded values are replaced with tokens. Specifically, there are no GUIDs in RGS files, e.g.:

    HKCR
    {
        NoRemove CLSID
        {
            ForceRemove %CLSID% = s '%DESCRIPTION%'
            {
                InprocServer32 = s '%MODULE%'
                {
                    val ThreadingModel = s 'Both'
                }
                val AppID = s '%APPID%'
                TypeLib = s '%LIBID%'
            }
        }
    }