From: Steve Achelis on
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!
From: David Ching on
"Steve Achelis" <info(a)RescueRigger.com> wrote in message
news:d6ecf273-246c-44f3-ba70-db7be002e097(a)i37g2000yqn.googlegroups.com...
> 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.
>

If in the IDE you run Tools | Error Lookup, you can easily see what '5'
means. It means "Access denied."

Since you are running Vista, the problem may be UAC is enabled and when your
app tries to associate the shell types, it is being denied since this
affects HKCR which requires Admin rights. You could run your program As
Administrator or change the manifest to require Admin rights in order to
execute to workaround this. I don't recommend the latter, since Admin
rights would not be needed after the first time the app is run and the shell
types are correctly set up.

The true way to fix this is to modify your installer (which always runs with
Admin rights) to set the shell types for you, and remove the call to
RegisterFileTypes() in your app.

-- David


From: Steve Achelis on
Thanks guys. I hadn't run into this before, probably because during
install they're running higher privileges so it gets set. I have been
calling this every time on startup (which has probably been failing
all along under Vista). I'll shift it to my setup program... And no, I
didn’t know about the nifty error lookup in VS2008. Sweet.
From: Tom Serface on
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(a)RescueRigger.com> wrote in message
news:d6ecf273-246c-44f3-ba70-db7be002e097(a)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!

 | 
Pages: 1
Prev: Strange CVSListBox behavior
Next: CEdit