Problem loading DLL
-
Hi! Does anyone know why would an extension DLL not load when using the following code?
if ( AfxLoadLibrary( "MyDLL.dll" ) == NULL ) AfxMessageBox( "Error loading library." );
So, MyDLL.dll is an extension DLL. AfxLoadLibrary always returns NULL, even though the calling process and MyDLL.dll are in the same directory. Any help will be greatly appreciated! Thanks in advance! -
Hi! Does anyone know why would an extension DLL not load when using the following code?
if ( AfxLoadLibrary( "MyDLL.dll" ) == NULL ) AfxMessageBox( "Error loading library." );
So, MyDLL.dll is an extension DLL. AfxLoadLibrary always returns NULL, even though the calling process and MyDLL.dll are in the same directory. Any help will be greatly appreciated! Thanks in advance!What does your DllMain look like in the extension DLL? Is initialization failing there? The app and the DLL are using the DLL version of MFC, correct? Mark
-
Hi! Does anyone know why would an extension DLL not load when using the following code?
if ( AfxLoadLibrary( "MyDLL.dll" ) == NULL ) AfxMessageBox( "Error loading library." );
So, MyDLL.dll is an extension DLL. AfxLoadLibrary always returns NULL, even though the calling process and MyDLL.dll are in the same directory. Any help will be greatly appreciated! Thanks in advance!Eikthrynir wrote:
...even though the calling process and MyDLL.dll are in the same directory.
Just for grins, try specifying an absolute path to
mydll.dll
. Is your app multithreaded?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
What does your DllMain look like in the extension DLL? Is initialization failing there? The app and the DLL are using the DLL version of MFC, correct? Mark
This is how my DllMain looks like:
extern "C" int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { // Remove this if you use lpReserved UNREFERENCED_PARAMETER(lpReserved); if (dwReason == DLL_PROCESS_ATTACH) { TRACE0("MYDLL.DLL Initializing!\n"); // Extension DLL one-time initialization if (!AfxInitExtensionModule(MyDLL, hInstance)) return 0; new CDynLinkLibrary(MyDLL); } else if (dwReason == DLL_PROCESS_DETACH) { TRACE0("MYDLL.DLL Terminating!\n"); // Terminate the library before destructors are called AfxTermExtensionModule(MyDLL); } return 1; // ok }
I even put these lines of code right at the begining of DllMain:CFile log; log.Open( "log.001", CFile::modeCreate | CFile::modeWrite, NULL ); log.Write( "@", 1 ); log.Close( );
I ran the program using the new version of mydll.dll and NO log.001 was created. So DllMain does not get executed. -
What does your DllMain look like in the extension DLL? Is initialization failing there? The app and the DLL are using the DLL version of MFC, correct? Mark
Problem solved!!!!!!!!!! MyDLL.dll was using another dll which did not exist. Thank you for your time!
-
This is how my DllMain looks like:
extern "C" int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { // Remove this if you use lpReserved UNREFERENCED_PARAMETER(lpReserved); if (dwReason == DLL_PROCESS_ATTACH) { TRACE0("MYDLL.DLL Initializing!\n"); // Extension DLL one-time initialization if (!AfxInitExtensionModule(MyDLL, hInstance)) return 0; new CDynLinkLibrary(MyDLL); } else if (dwReason == DLL_PROCESS_DETACH) { TRACE0("MYDLL.DLL Terminating!\n"); // Terminate the library before destructors are called AfxTermExtensionModule(MyDLL); } return 1; // ok }
I even put these lines of code right at the begining of DllMain:CFile log; log.Open( "log.001", CFile::modeCreate | CFile::modeWrite, NULL ); log.Write( "@", 1 ); log.Close( );
I ran the program using the new version of mydll.dll and NO log.001 was created. So DllMain does not get executed.You shouldn't need to write a log file. "MYDLL.DLL Initializing!" should show up in your debug output window. You could put a breakpoint in there as well. It's a mystery :) Have you tried David Crow's suggestion?
-
Problem solved!!!!!!!!!! MyDLL.dll was using another dll which did not exist. Thank you for your time!
Eikthrynir wrote:
MyDLL.dll was using another dll which did not exist.
Cool :-D