Thread: how do I handle a dll function that does not return?

  1. #1
    Registered User
    Join Date
    Nov 2010

    Question how do I handle a dll function that does not return?


    I am using visual C++ ver 8.

    I have written a application that calls a third party dll function that communicates to a connected embedded device via TCP/IP. This routine is ran around 14 times a second.

    Two/three weeks or so in, my application stops working due to a non return in the dll and appears to get stuck in a internal loop in the third party dll. The application does not crash, but I do need to perform a manual closedown and a restart to gets things going again.

    What is the best way to handle this? I know if I was using VB, I could maybe use a multi-threaded timer function to see if processing has stopped? However, I dont know how to do this in c++ or is is there a simpler method I could use?

    As its a third party dll I cant debug their issue, but I should be able to handle it within my app..

    I would appreciate your assistance?


  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    ...get stuck in a internal loop in the third party dll.
    Contact the vendor of the DLL and notify them of the problem. If you do not have the solution to re-build the DLL then you really cannot debug it, re-base it, or fix it.

    Even if the problem is your usage of the DLL I would still contact them since no DLL should ever get stuck in an infinite loop under any error conditions. At best it is not correctly handling an error condition.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Hi Bubba,

    Yes your correct. The dll should not be in an infinite loop in the first place. However, what is the manufacturers problem is now my problem.

    It seems to take a few days before it gets lost internally. So I should be able to use a handler to find the delay which will keep my application running smoothly.

    What I need to do is to find and handle the infinite loop. I would appreciate guidance or suggestions to how this can be done.

  4. #4
    Registered User
    Join Date
    May 2009
    This is just a random guess from a C programmer who does NOT work with DLLs very much.

    Is the DLL always loaded into memory?
    If yes, it might have a slow memory leak that causes a crash.

    If yes, It might be possible that using delayed loading or Explicit run-time linking of the DLL combined with unloading the DLL every few days might prevent the problem from happening.

    Tim S.
    Last edited by stahta01; 11-13-2010 at 05:12 PM. Reason: Added Explicit run-time linking

  5. #5
    Join Date
    Oct 2007
    Inside my computer
    It is possible to do this, but it isn't a good solution.
    You can create a separate thread for which to run the DLL function. Then wait for the thread to complete with a timeout with WaitForSingleObject. The return from the function indicates if the thread timed out or if it exited normally. If it timed out, you can kill the thread (eg TerminateThread). This will leak the stack for the thread, though, so it's not a really good solution.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 10:00 PM
  3. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 07:57 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM

Tags for this Thread