Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem loading DLL

Problem loading DLL

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eikthrynir
    wrote on last edited by
    #1

    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!

    D M 2 Replies Last reply
    0
    • E Eikthrynir

      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!

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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

      E 2 Replies Last reply
      0
      • E Eikthrynir

        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!

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • M Mark Salsbery

          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

          E Offline
          E Offline
          Eikthrynir
          wrote on last edited by
          #4

          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.

          M 1 Reply Last reply
          0
          • M Mark Salsbery

            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

            E Offline
            E Offline
            Eikthrynir
            wrote on last edited by
            #5

            Problem solved!!!!!!!!!! MyDLL.dll was using another dll which did not exist. Thank you for your time!

            M 1 Reply Last reply
            0
            • E Eikthrynir

              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.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              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?

              1 Reply Last reply
              0
              • E Eikthrynir

                Problem solved!!!!!!!!!! MyDLL.dll was using another dll which did not exist. Thank you for your time!

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                Eikthrynir wrote:

                MyDLL.dll was using another dll which did not exist.

                Cool :-D

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups