Malick
Malick

Reputation: 6742

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.

Upvotes: 1

Views: 1027

Answers (2)

Fredrik Orderud
Fredrik Orderud

Reputation: 309

I'm not able to understand how %CLSID% is replaced with the COM class CLSID in roman-r's answer. There seem to be something missing in the answer.

Alternative solution from CodeProject: Registry Map for RGS files. This solution introduces a custom registrymap.hpp header with a DECLARE_REGISTRY_RESOURCEID_EX extension that allows you to add RGS substitution macros to your COM classes. Example:

BEGIN_REGISTRY_MAP(CClassName)
    REGMAP_ENTRY("PROGID",      "MyLibrary.ClassName")
    REGMAP_ENTRY("VERSION",     "1")
    REGMAP_ENTRY("DESCRIPTION", "ClassName Class")
    REGMAP_UUID ("CLSID",       CLSID_ClassName)
    REGMAP_UUID ("LIBID",       LIBID_MyLibraryLib)
    REGMAP_ENTRY("THREADING",   "Apartment")
END_REGISTRY_MAP()

Upvotes: 1

Roman Ryltsov
Roman Ryltsov

Reputation: 69724

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%'
        }
    }
}

Upvotes: 4

Related Questions