=?Windows-1252?Q?Re:_Application_won't_launch_from_document?=
You may find this code to be useful. I add this to all of my programs now
to get the associations written to HKCU instead:
This goes in InitInstance()
OverrideHKCR();
RegisterShellFileTypes(true);
RestoreHKCR();
This goes wherever:
bool OverrideHKCR()
{
// If we can't write to HKEY_CLASSES_ROOT, we should try
// HKEY_CURRENT_USER\Software\Classes instead.
HKEY hkcr;
long ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Classes"), 0,
KEY_ALL_ACCESS, &hkcr);
if(ret != ERROR_SUCCESS) { // Need to override
HKEY hkcu;
ret = RegOpenKey(HKEY_CURRENT_USER, _T("Software\\Classes"), &hkcu);
if(ret == ERROR_SUCCESS) {
ret = RegOverridePredefKey(HKEY_CLASSES_ROOT, hkcu);
RegCloseKey(hkcu);
return ret == ERROR_SUCCESS;
}
}
else {
RegCloseKey(hkcr);
}
return false; // Didn't need to do this
}
void RestoreHKCU()
{
RegOverridePredefKey(HKEY_CLASSES_ROOT, NULL);
}
"Steve Achelis" <info@RescueRigger.com> wrote in message
news:d6ecf273-246c-44f3-ba70-db7be002e097@i37g2000yqn.googlegroups.com...
I?m porting an MFC VC 6.0 app to VS 2008. The application won?t launch
by opening one of its documents (i.e., the app?s file type isn?t
getting registered correctly).
My document string is defined as follows (no, my app isn?t really
named AppName <g>):
IDR_MAINFRAME "AppName\nSystems\nSystem\n AppName Files (*.rig)\n.rig
\n AppName System\n AppName "
In InitInstance() I have:
?
pDocTemplate = new CSingleDocTemplate( ? );
?
EnableShellOpen();
RegisterShellFileTypes(true);
?
If I step into RegisterShellFileTypes(true), I can see that a call to
_AfxSetRegKey() fails. (The failure happens in a call to
AfxRegSetValue () which returns 5.) This call posts the following
message to the Output window:
Warning: registration database update failed for key 'AppNameSystem'.
I?m running Vista with the latest updates.
Help? This one has beaten me up far too long.
Thanks!