I have the following in my DLL:
Code:MessageLogger *logger=NULL; HINSTANCE g_hmodThisDll = NULL; MessageLogger* getMessageLogger() { return logger; } BOOL APIENTRY DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved ) { switch (dwReason) { case DLL_PROCESS_ATTACH: { g_hmodThisDll = hInstance; logger = new MessageLogger; } break; case DLL_PROCESS_DETACH: if (logger) delete logger; break;
I am exporting MessageLogger* getMessageLogger() and the whole MessageLogger class.
MessageLogger has the following function:
Code:void MessageLogger::setFile(FILE * pFile) { m_pFile = pFile; }
My main executable calls getMessageLogger() to get a pointer to the MessageLogger created by the DLL.
Is this OK to do?
My main program then opens a file and passes the pointer to set file:
My problem is that pFile contains a bad pointer when it gets to the DLL. How do I pass this file pointer to the DLL?Code:FILE *f = fopen("DateTime.Log","w"); logger->setFile(f);




Reply With Quote