Loadlibrary fails for some dlls,works for others menu

User Tag List

Results 1 to 9 of 9
  1. #1
    streppel's Avatar Active Member
    Reputation
    78
    Join Date
    Mar 2007
    Posts
    196
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Loadlibrary fails for some dlls,works for others

    Hey all,

    i'm currently on making my Bot more Platform and Computer independent(and easier to keep up to date after a patch) with loading dlls myself and using GetProcAddress to get the adresse of methods.
    The problem here is that i can load some dlls, but not all i want. I load about 10 dlls all from the same Folder(game folder) without a problem, but when it comes down to the main dlls with the methods i want to use, it returns a 0 so i can't get the offset to the method.
    I used Marshal.GetLastWin32Error what returned 126(looked it up and it said that i can't find the module), but as it is in the same Folder as the others and the filename is written correctly, i really don't get why it's not working.

    any help on this would be great
    streppel

    Loadlibrary fails for some dlls,works for others
  2. #2
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since you are appearently using C# for your stuff...
    I'm pretty sure the CLR does internally uses LoadLibrary/GetProcAddress for implementing the [DllImport] functionality.
    Why fiddling around with that yourself? Also try Win32Exception for handling Win32 exceptions.

  3. #3
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could be any number of things. Post your code.

  4. #4
    streppel's Avatar Active Member
    Reputation
    78
    Join Date
    Mar 2007
    Posts
    196
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    static class NativeMethods
    {
    [DllImport("kernel32.dll")]
    public static extern IntPtr LoadLibrary(string dllToLoad);
    
    [DllImport("kernel32.dll")]
    public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
    
    
            [DllImport("kernel32.dll")]
            publicstaticexternbool FreeLibrary(IntPtr hModule);
    }
    
    and my Method:
    public void LoadLibs()
    {
          NativeMethods.LoadLibrary(Pathconst + "Filename.dll"); // ofc checked if Pathconst is correct etc etc,everything right here
    }
    this works like i said,for some dlls, but not for others

    EDIT:
    ok i did it another way now(using the games GetProcAddress method instead of loading the dlls in my bot and gettings offsets from there etc etc) which works too,but still i'd like to know why it wasn't working with loading the dll directly
    Last edited by streppel; 10-07-2011 at 08:17 AM.

  5. #5
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, but I still don't get why you would want to do this.
    Decorating your stuff with DllImport is far easier than Load/FreeLibrary it yourself.

    If you want to know how to load a dll at a dynamic (= changing) location, try out Reflection.Emit (see Late binding on native DLLs with C# - CodeProject).
    There is really no need to use Load/FreeLibrary for that sort of stuff, especially because you might end up doing something wrong (managed people are too lazy).

  6. #6
    streppel's Avatar Active Member
    Reputation
    78
    Join Date
    Mar 2007
    Posts
    196
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm using asm code injection to do my stuff ingame(targeting,casting etc), but for this i have to get the adress at which the methods i want to use are. To get these adresses i wanted to load the library,run getprocaddress on it with the symbol of the method as 2nd argument, and in return, get the offset for the method. then i could simply find the location of the dll in the other process,add the offset and use this adresse for the asm stuff(aka call 0xdeadbeef).
    and i didn't want to use static adresses cause this way it's much easier to maintain after patches(symbols tend to stay to same if there was nothing big changed(aka return type,name or arguments), so doing this work once will save me lots of work later

    i hope you got it now

  7. #7
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah ok... makes sense

  8. #8
    _Mike's Avatar Contributor
    Reputation
    310
    Join Date
    Apr 2008
    Posts
    531
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by streppel View Post
    I used Marshal.GetLastWin32Error what returned 126(looked it up and it said that i can't find the module), but as it is in the same Folder as the others and the filename is written correctly, i really don't get why it's not working.
    Iirc you will get that same error if it fails to find all of the DLL's dependencies.

  9. #9
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2012, 08:23 PM
  2. Some screenshots I shot for others
    By quinnie in forum Screenshot & Video Showoff
    Replies: 19
    Last Post: 01-31-2009, 12:42 AM
  3. Fishing guide - 100g for 10 minutes work among others
    By gareer in forum World of Warcraft Guides
    Replies: 7
    Last Post: 09-30-2008, 09:37 AM
  4. Need Some Art Work For New Website
    By bomber1392 in forum Art & Graphic Design
    Replies: 13
    Last Post: 10-04-2007, 10:11 PM
All times are GMT -5. The time now is 12:43 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search