Re: Using MFC dll from non-MFC application
What sort of DLL is it? Regular or MFC Extension. It should be a
Regular DLL and you should use AFX_MANAGE_STATE to change the state as
needed.
---
Ajay
Thank you for responding Ajay. Yes, I am using a regular dll since I need
to call it from a non-MFC program. From what I understand, I only need the
AFX_MANAGE_STATE if I am linking to MFC dynamically. But just to be sure I
have it in anyway, but it doesn't help. It crashes with or without it. Here
is the code with the hook function to the application and InitInstance. I
tried to strip it down as much as possible. Anybody see anything that looks
fishy?
Thank you.
/////////////////////////////////////////////////////////////////////////////
// The one and only CViewPointCloudApp object
CViewPointCloudApp theApp;
extern "C" {
__declspec(dllexport) void ViewPointCloud (void);
void ViewPointCloud (void)
{
AFX_MANAGE_STATE (AfxGetStaticModuleState());
theApp.Run();
}
} // extern "C"
BOOL CViewPointCloudApp::InitInstance()
{
CWinApp::InitInstance();
AfxEnableControlContainer();
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CViewPointCloudDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CViewPointCloudView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}