Reputation: 1363
Any call on my application to AfxGetApp() returns NULL, can anyone help?
It is a .exe project converted from a .dll project, so there may be some project configurations that I am missing. I have copied configurations from another project created with the .exe wizard but is does not work. Also, I have a CWinApp that is global.
Upvotes: 2
Views: 4338
Reputation: 31
I had a similar problem building a dll, if I copy this code (taken from another dll) AfxGetApp() returns the correct pointer:
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
}
return nRetCode;
}
Upvotes: 2