How to loadlibrary from a new thread

This is a discussion on How to loadlibrary from a new thread within the Windows Programming forums, part of the Platform Specific Boards category; Hello everyone, I've searched the forum for an answer to my newbie question, but found nothing directly related to it...although ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Location
    hellertown, pennsylvania
    Posts
    24

    How to loadlibrary from a new thread

    Hello everyone,

    I've searched the forum for an answer to my newbie question, but found nothing directly related to it...although lots of good stuff about DLL's.

    In my little program in the main() I successfully use LoadLibrary and GetProcAddress and call a couple of functions in a DLL. In short, the DLL works as such. Then, I CreateThread(...) and create a new thread. The function called by CreateThread attempts to do a LoadLibrary and GetProcAddress to the SAME DLL. Nothing happens. No error messages, no nothing. The function invoked by CreateThread gets to the line in which LoadLibrary is called and does nothing. Program exits without errors.

    The DLL itself has a BOOL WINAPI DllMain entry point with the "usual" DLL_PROCESS_ATTACH, etc. values in a switch block.

    It seems like what I'm trying to do should work, but it doesn't. I have zero tech support, and I'm out of ideas.

    Thanks for considering this problem.

    Regards to all,
    Mark Allyn

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Have you tried passing the address of the DLL that you got from the first LoadLibrary into the function that is being run by the new thread?

    DLLs are loaded into the address space of the entire process so you don't really need to call LoadLibrary again unless the main thread might unload the library before the second thread is done with it.

    Are you sure that the functions you're calling aren't working properly? Is there a reason that the program should stay open for longer than that?

  3. #3
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    Isn't it a platform specific thread?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    Moved to Windows Programming.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    What does GetLastError() return?

    Generally DDLs loaded at runtime (dynamically) should either;

    have global scope (loaded once and passed around as required)

    or

    loaded, used and released as required.

    This depends on the requirements of the app and the DLL.

    Also IIRC once a process has called LoadLibrary() on a particular DLL (and so 'mapped' it) the DLLMain() will not get called again by the same process (until the DLL is unmapped with a call to FreeLibrary() ).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-26-2009, 10:48 PM
  2. Terminating secondary thread from another thread
    By wssoh85 in forum C++ Programming
    Replies: 13
    Last Post: 12-19-2008, 04:14 AM
  3. CreateThread ?!
    By Devil Panther in forum Windows Programming
    Replies: 13
    Last Post: 11-15-2005, 09:55 AM
  4. pointer to main thread from worker thread?
    By draegon in forum C++ Programming
    Replies: 2
    Last Post: 10-27-2005, 06:35 AM
  5. Critical Sections, destroying
    By Hunter2 in forum Windows Programming
    Replies: 4
    Last Post: 09-02-2003, 10:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21