dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2003
    Posts
    731

    [RESOLVED] Can we create threads in Dll?

    I understand we can call any API's inside a DLL but just curious can we create threads as well? For example we call a function from the dll and that function in turn create some thread (like serial port input thread). Can we do that?

  2. #2
    Join Date
    Aug 1999
    Location
    Germany
    Posts
    2,338

    Re: Can we create threads in Dll?

    I know no reason why this shouldn't be possible.

  3. #3
    Join Date
    Feb 2002
    Posts
    5,757

    Re: Can we create threads in Dll?

    Definitely! A process maps a DLL into its address spaces. Threads created within the DLL are part of the host's process address spaces.

    Kuphryn

  4. #4
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Can we create threads in Dll?

    Yes. Why not ?

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Can we create threads in Dll?

    [ Moved thread ]

  6. #6
    Join Date
    Jun 2009
    Posts
    1

    Re: Can we create threads in Dll?

    how?
    I created a DLL in which it creates several threads, but when I use it in an MFC project, it always gets crashed, both in Debug mode and Release mode.
    I changed this DLL to a single win32 console project, it runs correctly both in Debug and Release mode.
    What's the trick creating multiple threads in dll?

    Thanks,
    Yuping

  7. #7
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Can we create threads in Dll?

    There is no trick to it. It sounds like there's a bug somewhere in your DLL (or EXE). What crashes and where? Have you looked at it in the debugger?

    Viggy

  8. #8
    Join Date
    Apr 2018
    Location
    UK
    Posts
    2

    Re: Can we create threads in Dll?

    Hi, I know this is an old thread. I am working on porting an old win32 DLL to support win64. Part of this update requires replacement of an API, the new API uses threads for background functions. I have tried creating the threads in the DLL and found that despite _beginthreadex returning a valid handle the thread doesn't run. I'm Attaching to the DLL using Visual Studio and I can see the call to _beginthreadex is successful but the thread body never runs.

    I've put the same code into a standalone application and it works fine, what could the problem be?

  9. #9
    Join Date
    Apr 2018
    Location
    UK
    Posts
    2

    Re: Can we create threads in Dll?

    Solved....In DllMain there was a call to DisableThreadLibraryCalls(hInstance), which I missed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)