ATL provides registration for your application's basic COM objects and type library. You must provide additional registration for your Design Center customizations.
This method of adding registry entries is not Microsoft logo compliant. Power User privileges will be required to install the resulting application. The preferred alternative is to have your MSI installer write the required registry entries.
Add the following registry initialization function to AsdkDesignCenterSamp.cpp. This function will set up the registry based on registry resources that will be added in a later step.
void registerAppInfo(HINSTANCE hInstance) { USES_CONVERSION; HRESULT hRes = S_OK; CComPtr<IRegistrar> p; hRes = CoCreateInstance(CLSID_Registrar, NULL, CLSCTX_INPROC_SERVER, IID_IRegistrar, (void**)&p); if(SUCCEEDED(hRes)) { // Get the AutoCAD Product key from the // registry into a CString. // CString csProdKey = acrxProductKey(); // Replace the run-time strings // TCHAR szRegKey[MAX_PATH]; tcscpy(szRegKey, csProdKey); const TCHAR *pszDelimiter = "\\"; TCHAR *pszToken = _tcstok(szRegKey, pszDelimiter); const TCHAR *pszIds[] = { "RELEASE", "AUTH" }; pszToken = _tcstok(NULL, pszDelimiter); pszToken = _tcstok(NULL, pszDelimiter); pszToken = _tcstok(NULL, pszDelimiter); int nCount = 0; while(NULL != pszToken) { p->AddReplacement(T2OLE(pszIds[nCount]), T2OLE(pszToken)); pszToken = _tcstok(NULL, pszDelimiter); if(NULL == pszToken) break; nCount++; } _TCHAR szModule[_MAX_PATH]; GetModuleFileName(hInstance, szModule, _MAX_PATH); LPCOLESTR szType = OLESTR("REGISTRY"); LPOLESTR pszModule = T2OLE(szModule); // Pull the registry entries from the resource ID. // hRes = p->ResourceRegister(pszModule, IDR_REGISTRY1, szType); if(FAILED(hRes)) AfxMessageBox("Error registering the app info."); } }
In the InitInstance() function, call DllRegisterServer() and registerAppInfo(). Pass the instance handle member to registerAppInfo(). A typical implementation of InitInstance() is shown below:
BOOL CAsdkDesignCenterSampApp::InitInstance() { DllRegisterServer();registerAppInfo(m_hInstance);return CWinApp::InitInstance(); }
Using Visual Studio's wizard interface, add a new simple ATL Object that will support the IAcDcContentView interface. For this example, call it AsdkDcContent. On the appropriate wizard page, select the option to support ISupportErrorInfo. Close the wizard.
Add registry information to the resource section of the project. First, open the generated file called AsdkDesignCenterSamp.rgs. Replace its contents with the following listing. This listing should be changed to suit your project, where the “<Your CLSID>” string should be replaced with the class ID (CLSID) from your IDL file. Use the CLSID that represents the coclass of your IAsdkDcContent interface. Since these are GUID values, they are different for each new project. Also, for other projects, you will need to change the extensions sections and also add the name of your class. Again, this example uses AsdkDcContent.
HKLM { NoRemove 'SOFTWARE' { NoRemove 'Autodesk' { NoRemove 'AutoCAD' { NoRemove '%RELEASE%' { NoRemove '%AUTH%' { NoRemove 'AutodeskApps' { NoRemove 'AcadDC' { NoRemove 'Extensions' { ForceRemove '.txt' { val CLSID = s '{<Your CLSID>}' val IconIndex = d '0' } } NoRemove 'Applications' { ForceRemove 'AsdkDcContent' { 'Extensions' { .txt { val CLSID = s '{<Your CLSID>}' val IconIndex = d '0' } } CustomView = s 'Yes' } } } } } } } } } }
Save this file and, in Visual Studio, go to the project's Resource View. Open the AsdkDesignCenterSamp.rc node, and expand the Registry node. Click the IDR_ASDKDESIGNCENTERSAMP resource to display its contents. It should now show the information that you added in step 4. If the information is incorrect, you can add a new registry resource and import the registry file by right-clickng the AsdkDesignCenterSamp.rc node. The imported data should be assigned a resource ID of IDR_REGISTRY1; if not, rename it so that it matches the ID provided to the IRegistrar::ResourceRegister() call in your registerAppInfo() function.
In the constructor for your CAsdkDesignCenterSampModule class, verify that the DECLARE_REGISTRY_APPID_RESOURCEID macro uses the IAcDcContentView coclass registry resource ID as its first argument, rather than the new ID created in step 5. For instance, if you named your ATL object AsdkDcContent as suggested in step 3, the proper resource ID should be IDR_ASDKDCCONTENT.