Invoking Scripts

The previous section, Using Replaceable Parameters (The Registrar's Preprocessor), discussed replacement maps and introduced two of the Registrar's methods, AddReplacement and ClearReplacements. The Registrar has eight other methods specific to scripting. All eight of these methods are described in the following table and invoke the Registrar on a particular script.

Method Syntax/Description
ResourceRegister HRESULT ResourceRegister( LPCOLESTR resFileName, UINT nID, LPCOLESTR szType );

Registers the script contained in a module's resource. resFileName indicates the UNC path to the module itself. nID and szType contain the resource's ID and type, respectively.

ResourceUnregister HRESULT ResourceUnregister( LPCOLESTR resFileName, UINT nID, LPCOLESTR szType );

Unregisters the script contained in a module's resource. resFileName indicates the UNC path to the module itself. nID and szType contain the resource's ID and type, respectively.

ResourceRegisterSz HRESULT ResourceRegisterSz( LPCOLESTR resFileName, LPCOLESTR szID, LPCOLESTR szType );

Registers the script contained in a module's resource. resFileName indicates the UNC path to the module itself. szID and szType contain the resource's string identifier and type, respectively.

ResourceUnregisterSz HRESULT ResourceUnregisterSz( LPCOLESTR resFileName, LPCOLESTR szID, LPCOLESTR szType );

Unregisters the script contained in a module's resource. resFileName indicates the UNC path to the module itself. szID and szType contain the resource's string identifier and type, respectively.

FileRegister HRESULT FileRegister( LPCOLESTR fileName );

Registers the script in a file. fileName is a UNC path to a file that contains (or is) a resource script.

FileUnregister HRESULT FileUnregister( LPCOLESTR fileName );

Unregisters the script in a file. fileName is a UNC path to a file that contains (or is) a resource script.

StringRegister HRESULT StringRegister( LPCOLESTR data );

Registers the script in a string. data contains the script itself.

StringUnregister HRESULT StringUnregister( LPCOLESTR data );

Unregisters the script in a string. data contains the script itself.


ATL uses the first two methods shown in the table (ResourceRegister and ResourceUnregister) in atlimpl.cpp:

LPCOLESTR szType = OLESTR("REGISTRY");
GetModuleFileName(pM->m_hInstResource, szModule, _MAX_PATH);
LPOLESTR pszModule = T2OLE(szModule);

if (HIWORD(lpszRes)==0)
{
   if (bRegister)
     hRes = p->ResourceRegister(pszModule, 
               ((UINT)LOWORD((DWORD)lpszRes)), szType);
   else
     hRes = p->ResourceUnregister(pszModule, 
               ((UINT)LOWORD((DWORD)lpszRes)), szType);
}
else
{
   if (bRegister)
     hRes = p->ResourceRegisterSz(pszModule, lpszRes, szType);
   else
     hRes = p->ResourceUnregisterSz(pszModule, lpszRes, szType);
}

Note that szModule contains the value acquired from GetModuleFileName.

The next two methods shown in the table, ResourceRegisterSz and ResourceUnregisterSz, are similar to ResourceRegister and ResourceUnregister, but allow you to specify a string identifier.

The methods FileRegister and FileUnregister are useful if you do not want the script in a resource or if you want the script in its own file. The methods StringRegister and StringUnregister allow the .rgs file to be stored in a dynamically-allocated string.