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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. problem:dll not found

problem:dll not found

Scheduled Pinned Locked Moved C / C++ / MFC
help
11 Posts 4 Posters 1 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.
  • H happycpp

    hi everyone... i have this little problem i hope you can help me with.it's as follows: i'm making a dll that contains a lot of functions..these functions work on both xp and 9x except for one function ((suppose it's fn1)) that works only on xp((this function uses SetLayeredWindowAttributes))...the problem is when building the dll with fn1 and then trying to use a not fn1 function on win9x an error message appears reporting that the dll is not found!!!!after building without fn1 the dll works properly...i want to be able to use the 9x supported function of the dll even if it's built with fn1... note:there are no problems at all on winxp...

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

    Change fn1() to explicitly load user32.lib via LoadLibrary() and use GetProcessAddress() for SetLayeredWindowAttributes(). Something like:

    fn1()
    {
    HINSTANCE hLibrary = LoadLibrary("user32.dll");
    if (NULL != hLibrary)
    {
    typedef BOOL (*SETLAYEREDWINDOWATTRIBUTES)(HWND, COLORREF, BYTE, DWORD);
    SETLAYEREDWINDOWATTRIBUTES pSetLayeredWindowAttributes;
    pSetLayeredWindowAttributes = (SETLAYEREDWINDOWATTRIBUTES) GetProcAddress(hLibrary, "SetLayeredWindowAttributes");
    if (NULL != pSetLayeredWindowAttributes)
    *(pSetLayeredWindowAttributes)(...);

        FreeLibrary(hLibrary);
    }
    

    }


    "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

    H 1 Reply Last reply
    0
    • D David Crow

      Change fn1() to explicitly load user32.lib via LoadLibrary() and use GetProcessAddress() for SetLayeredWindowAttributes(). Something like:

      fn1()
      {
      HINSTANCE hLibrary = LoadLibrary("user32.dll");
      if (NULL != hLibrary)
      {
      typedef BOOL (*SETLAYEREDWINDOWATTRIBUTES)(HWND, COLORREF, BYTE, DWORD);
      SETLAYEREDWINDOWATTRIBUTES pSetLayeredWindowAttributes;
      pSetLayeredWindowAttributes = (SETLAYEREDWINDOWATTRIBUTES) GetProcAddress(hLibrary, "SetLayeredWindowAttributes");
      if (NULL != pSetLayeredWindowAttributes)
      *(pSetLayeredWindowAttributes)(...);

          FreeLibrary(hLibrary);
      }
      

      }


      "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

      H Offline
      H Offline
      happycpp
      wrote on last edited by
      #3

      i think this idea works..but i think it's like working around the problem...it's like healing symptoms and forget about the disease...isn't there some better idea..

      D 1 Reply Last reply
      0
      • H happycpp

        i think this idea works..but i think it's like working around the problem...it's like healing symptoms and forget about the disease...isn't there some better idea..

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

        Actually, it's the preferred method for having a single DLL work on multiple platforms. You can always create multiple DLLs, one with the function and one without.


        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

        H 1 Reply Last reply
        0
        • D David Crow

          Actually, it's the preferred method for having a single DLL work on multiple platforms. You can always create multiple DLLs, one with the function and one without.


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          H Offline
          H Offline
          happycpp
          wrote on last edited by
          #5

          the dynamic-loading way didn't work!!!i don't know why.. i get this error: run-time check failure #0 - the value of ESP was not properly saved across a function call. this is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. note:the functions in the dll use _stdcall convention to be used with VB...

          D 1 Reply Last reply
          0
          • H happycpp

            the dynamic-loading way didn't work!!!i don't know why.. i get this error: run-time check failure #0 - the value of ESP was not properly saved across a function call. this is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. note:the functions in the dll use _stdcall convention to be used with VB...

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

            See if this article helps.


            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

            B 1 Reply Last reply
            0
            • D David Crow

              See if this article helps.


              "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

              B Offline
              B Offline
              Blake Miller
              wrote on last edited by
              #7

              This reminds me of MY current problem, where I need to put some functions in a DLL AND dynamically link to my own functions just to call two Microsoft APIs. I need to know if there are instances of MSDE on a machine. Using the 'preferred' functions NumInstalledInstances and IsInstanceNameValid. These are in a static LIB file you link against. That's fine. But, when you execute them, they need a DLL that is only installed if the machine ALREADY has one or more of their dependent MSDE DLLs. So, if you want your EXE to load, you can't directly link with these functions, and so you put the functions in a DLL, but you can't statically link with your own DLL either, or you will still end up requiring the MSDE DLLs to load. So, you put the functions in your own DLL (which is statically linked to the Microsoft API), export some functions similar to the 'static' functions from the Microsoft API, and then DYNAMICALLY get the procedure address at runtime of your own two functions after dynamically loading your own DLL. Yeeeeeehaw! Aint this fun!

              L 1 Reply Last reply
              0
              • B Blake Miller

                This reminds me of MY current problem, where I need to put some functions in a DLL AND dynamically link to my own functions just to call two Microsoft APIs. I need to know if there are instances of MSDE on a machine. Using the 'preferred' functions NumInstalledInstances and IsInstanceNameValid. These are in a static LIB file you link against. That's fine. But, when you execute them, they need a DLL that is only installed if the machine ALREADY has one or more of their dependent MSDE DLLs. So, if you want your EXE to load, you can't directly link with these functions, and so you put the functions in a DLL, but you can't statically link with your own DLL either, or you will still end up requiring the MSDE DLLs to load. So, you put the functions in your own DLL (which is statically linked to the Microsoft API), export some functions similar to the 'static' functions from the Microsoft API, and then DYNAMICALLY get the procedure address at runtime of your own two functions after dynamically loading your own DLL. Yeeeeeehaw! Aint this fun!

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

                i got a headache of that..i'm a newbee to these stuff so please give me some more details about what to link statically and what to link dynamically.. i'm using static linking between my c++ dll and APIs contained in it.and using the usual Declare statement in VB to call my dll's functions..what necessary steps i need to make to solve the problem.. note:the article suggests writnig something like: typedef BOOL (* _stdcall fnptr) (HWND, COLORREF, BYTE, DWORD); but this didn't work either..

                B 1 Reply Last reply
                0
                • L Lost User

                  i got a headache of that..i'm a newbee to these stuff so please give me some more details about what to link statically and what to link dynamically.. i'm using static linking between my c++ dll and APIs contained in it.and using the usual Declare statement in VB to call my dll's functions..what necessary steps i need to make to solve the problem.. note:the article suggests writnig something like: typedef BOOL (* _stdcall fnptr) (HWND, COLORREF, BYTE, DWORD); but this didn't work either..

                  B Offline
                  B Offline
                  Blake Miller
                  wrote on last edited by
                  #9

                  The code wihtint he C++ DLL needs to load the library, like suggested earlier, then use GetProcAddress to obtaint he function from it, and only call the function if it gets the address, otherwise, you are on a version of the OS that doe snot have the function supported yet. Something like this: VB can statically link to C++ DLL C++ DLL dynamically loads library and gets procedure address If procedure address exists, then function is called, otherwise, it is not (obviously..) Then it will work, and you can load your VB application without the error about 'function not found' coming up.

                  H 1 Reply Last reply
                  0
                  • B Blake Miller

                    The code wihtint he C++ DLL needs to load the library, like suggested earlier, then use GetProcAddress to obtaint he function from it, and only call the function if it gets the address, otherwise, you are on a version of the OS that doe snot have the function supported yet. Something like this: VB can statically link to C++ DLL C++ DLL dynamically loads library and gets procedure address If procedure address exists, then function is called, otherwise, it is not (obviously..) Then it will work, and you can load your VB application without the error about 'function not found' coming up.

                    H Offline
                    H Offline
                    happycpp
                    wrote on last edited by
                    #10

                    it's not working man... i uploaded the project so you can download it and see what's wrong... after downloading you should build the dll and build the VB example project to the debug folder... the project

                    H 1 Reply Last reply
                    0
                    • H happycpp

                      it's not working man... i uploaded the project so you can download it and see what's wrong... after downloading you should build the dll and build the VB example project to the debug folder... the project

                      H Offline
                      H Offline
                      happycpp
                      wrote on last edited by
                      #11

                      that's is fantastic...i don't know how to thank you.. this forum is the best and you people are the best...:):)

                      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