Question:

C++ thread calling dll function help!?

by  |  earlier

0 LIKES UnLike

Very quickly:

I have a C++ program, it calls a dll that contains some external functions through a *.h & *.lib (meaning I don't have the source).

So, I want to add threading. So I use AfxBeginThread and try.

When my thread calls a certain function say "foo(ptr)". It returns a valid response, but the value of "ptr" is supposed to be changed -- its not.

But same code, simply called from the main-thread works -- ptr is the proper value.

Is there a reason why a thread wont work correctly with an external dll ?

 Tags:

   Report

3 ANSWERS


  1. That depends on the function that you're calling.

    Your foo(ptr); function is just an example, and you didn't give the name of the .dll and the function that you're calling in the .dll.

    Threads have full access to the main thread's data, and you can call functions from .dlls in threads created by the main thread.  If that were not the case, then you wouldn't be able to call Windows functions from child threads, which wouldn't make threads very useful.

    You should only use threads in certain situations, and your explanation about 'external function through a *.h & *.lib' does not make any sense.  I think you should learn more about .dlls and importing functions before messing with threads.

    I recommend this book:

    http://www.microsoft.com/mspress/books/2...

    Also, trying to program Windows with anything other than the Windows API functions produces incredibly bloated, slow code.

    On top of that, after learning to use idiotic functions provided by frameworks, you still wouldn't know how to truly program Windows.  The Windows API is all that you need.


  2. just put everything on the same project (separated by .h and .cpp files)

  3. When you're writing Windows software, the "main thread" is different than other threads that you create.  I'm not sure why this is, because on every other operating system, all threads are equivalent.

    So, my advice is to do all calls to dlls and other operating system functions in the main thread, and only use the threads you create for things that are totally internal to your application.

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.