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#
  4. LoadLibraryW(dllpath) fails

LoadLibraryW(dllpath) fails

Scheduled Pinned Locked Moved C#
csharp
8 Posts 4 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.
  • V Offline
    V Offline
    V K 2
    wrote on last edited by
    #1

    We are calling LoadLibary in C#. For this we have included the below code in the C# file. [DllImport("Kernel32.dll")] internal static extern IntPtr LoadLibraryW([MarshalAs(UnmanagedType.LPWStr)] String lpMdoule); We have multiple LoadLibaryW( ) calls. All of them are passing , except one. We verified the GetLastError( ). It returns 126. But the dll is physically existing in the correct path. What could be the reason for dll failure.

    P L 2 Replies Last reply
    0
    • V V K 2

      We are calling LoadLibary in C#. For this we have included the below code in the C# file. [DllImport("Kernel32.dll")] internal static extern IntPtr LoadLibraryW([MarshalAs(UnmanagedType.LPWStr)] String lpMdoule); We have multiple LoadLibaryW( ) calls. All of them are passing , except one. We verified the GetLastError( ). It returns 126. But the dll is physically existing in the correct path. What could be the reason for dll failure.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      The likeliest problem is that something the DLL you are trying to load relies on can't be found in the path.

      *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      V 1 Reply Last reply
      0
      • P Pete OHanlon

        The likeliest problem is that something the DLL you are trying to load relies on can't be found in the path.

        *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

        "Mind bleach! Send me mind bleach!" - Nagy Vilmos

        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

        V Offline
        V Offline
        V K 2
        wrote on last edited by
        #3

        The dll is physically existing in the desired path. But still LoadLibraryW( ) fails.

        P D 2 Replies Last reply
        0
        • V V K 2

          The dll is physically existing in the desired path. But still LoadLibraryW( ) fails.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Did you read my answer? I said that something the DLL relies on is probably outside the path.

          *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

          1 Reply Last reply
          0
          • V V K 2

            The dll is physically existing in the desired path. But still LoadLibraryW( ) fails.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            .DLL's sometimes are not standalone modules. It's entirely possible the .DLL you're trying to load uses another .DLL that you don't have somewhere where it can be found. Use this[^] to find out what that dependancy might be. Just open the .DLL that's failing in it.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            1 Reply Last reply
            0
            • V V K 2

              We are calling LoadLibary in C#. For this we have included the below code in the C# file. [DllImport("Kernel32.dll")] internal static extern IntPtr LoadLibraryW([MarshalAs(UnmanagedType.LPWStr)] String lpMdoule); We have multiple LoadLibaryW( ) calls. All of them are passing , except one. We verified the GetLastError( ). It returns 126. But the dll is physically existing in the correct path. What could be the reason for dll failure.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              The error code means that the file cannot be found. As I requested in the C++ forum, please show the exact code (including the string parameter) of the call that fails. We cannot guess what is happening inside your program. At a (bad) guess, based on what you wrote in the C++ forum, your code looks like:

              LoadLibaryW("C:\abc.dll");

              which will most likely fail as the backslash needs to be escaped.

              Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

              V 1 Reply Last reply
              0
              • L Lost User

                The error code means that the file cannot be found. As I requested in the C++ forum, please show the exact code (including the string parameter) of the call that fails. We cannot guess what is happening inside your program. At a (bad) guess, based on what you wrote in the C++ forum, your code looks like:

                LoadLibaryW("C:\abc.dll");

                which will most likely fail as the backslash needs to be escaped.

                Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                V Offline
                V Offline
                V K 2
                wrote on last edited by
                #7

                The exact path is LoadLibraryW("C:\\Program Files\\MyApp\\");

                P 1 Reply Last reply
                0
                • V V K 2

                  The exact path is LoadLibraryW("C:\\Program Files\\MyApp\\");

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #8

                  Where's the DLL name? You've just provided a path there - there's no DLL details, so how can you expect LoadLibraryW to pick up the DLL?

                  *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                  "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                  My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                  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