Getting problem with RegisterShellFileTypes() in MFC Dialog based application. [modified]
-
i created one dialog based application. In that Dlg App class i am calling RegisterShellFileTypes(), in CWInApp::initInstace. But application is crashing due to no poniter to document class. code is like this :
CDesktopWallpaperDlg dlg; m\_pMainWnd = &dlg; EnableShellOpen(); RegisterShellFileTypes(); INT\_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel }
so, can anyone tell me what is the problem exactly? it working with SDI Application..
Regards, Srinivas
modified on Thursday, December 3, 2009 6:24 AM
-
i created one dialog based application. In that Dlg App class i am calling RegisterShellFileTypes(), in CWInApp::initInstace. But application is crashing due to no poniter to document class. code is like this :
CDesktopWallpaperDlg dlg; m\_pMainWnd = &dlg; EnableShellOpen(); RegisterShellFileTypes(); INT\_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel }
so, can anyone tell me what is the problem exactly? it working with SDI Application..
Regards, Srinivas
modified on Thursday, December 3, 2009 6:24 AM
The problem is precisely what the error message says. RegisterShellFileTypes creates registry entries to associate a document type and file extension with an .exe. If you aren't using the MFC DocView framework, there is no document class and the function call fails. You can make the same registry entries manually; just because you aren't using the DocView framework doesn't mean you can't associate a file extension with an app, it just takes a bit more code.
-
i created one dialog based application. In that Dlg App class i am calling RegisterShellFileTypes(), in CWInApp::initInstace. But application is crashing due to no poniter to document class. code is like this :
CDesktopWallpaperDlg dlg; m\_pMainWnd = &dlg; EnableShellOpen(); RegisterShellFileTypes(); INT\_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel }
so, can anyone tell me what is the problem exactly? it working with SDI Application..
Regards, Srinivas
modified on Thursday, December 3, 2009 6:24 AM
It seems RegisterShellFileTypes() is to be used with SDI or MDI apps only.
-
The problem is precisely what the error message says. RegisterShellFileTypes creates registry entries to associate a document type and file extension with an .exe. If you aren't using the MFC DocView framework, there is no document class and the function call fails. You can make the same registry entries manually; just because you aren't using the DocView framework doesn't mean you can't associate a file extension with an app, it just takes a bit more code.
when i call this RegisterShellFileTypes() in App Class, internally in this function defination having pointer of document class. but dlg based application doesn't have doc class. so that, pointer is becoming NULL.
void CWinApp::RegisterShellFileTypes(BOOL bCompat)
{
ASSERT(m_pDocManager != NULL);
m_pDocManager->RegisterShellFileTypes(bCompat);
}but,it is working fine with SDI Application. i have tried in one sample SDI application.
Regards, Srinivas
-
when i call this RegisterShellFileTypes() in App Class, internally in this function defination having pointer of document class. but dlg based application doesn't have doc class. so that, pointer is becoming NULL.
void CWinApp::RegisterShellFileTypes(BOOL bCompat)
{
ASSERT(m_pDocManager != NULL);
m_pDocManager->RegisterShellFileTypes(bCompat);
}but,it is working fine with SDI Application. i have tried in one sample SDI application.
Regards, Srinivas
-
Yeah.... and what does SDI stand for? 'Single Document Interface'. It works in an SDI app because the SDI app has a document class, and fails in your dialog app because it doesn't have a document class.