Announcement

Collapse
No announcement yet.

Order of functions being called

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Order of functions being called

    I have a bit of a "Catch-22" that an EXE calls a DLL that in the DLL is a tight loop and even though I am using a Global variable as a Flag to escape, the flag is not set until the function ends. (Yes I know do not get me started on globals )

    Anyways, from Messageboxes I have determined that LibMain does not fire the %DLL_PROCESS_DETACH until after I have physically clicked a button to set the flag, so I can not programmatically set the flag, nor simulate a click to set the flag.

    I thought about checking IsWindow, and pass the handle to the parent exe into the functions, but that does me no good if there is no parent window or the parent is the desktop.

    I even thought about the hInstance, but since a dll is mapped into the parent instance, that does me no good either.

    Is there some windows api that I can use to determine if the "Parent" is closing, so I can cleanly stop any routines that are not seeing the flag set? If it weren't for the idea that all the functions are in the same thread, I would look deeper at MCM's Waitable objects and being cancelled, but the size of the project is too huge to re-write from scratch, and a new project (I hope to make better since I can start it from scratch) takes priority.

    Anyways anyone with a temporary work-around, help would be much appreciated
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    Create a hidden window from the DLL and set the shutdown flag from the WM_DESTROY message in the callback. There may be other "objects" (mutexes, etc.) that windows will free before DLL_PROCESS_DETACH is sent, but the hidden window is the way I would do it

    Remember: You must register a class and specify the DLL's hInstance as the class hInstance for it to be removed as the DLL is unloaded.
    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

    Comment


    • #3
      I tried that...(Unless I mis-understood)

      but the problem is LibMain with the %DLL_PROCESS_DETACH is what kicks everything off, but it can not kick off if the function is not fired until after I physically stop any tight loop function.

      maybe if I can thread certain functions, I can set the flag and the main flag can be seen?
      Engineer's Motto: If it aint broke take it apart and fix it

      "If at 1st you don't succeed... call it version 1.0"

      "Half of Programming is coding"....."The other 90% is DEBUGGING"

      "Document my code????" .... "WHYYY??? do you think they call it CODE? "

      Comment


      • #4
        Ok, I have a workable point to work from.

        Doc's say that LibMain is not guaranteed to be called, nor the order it is called in. (GRRRRRRR....)

        If I add one more function to purposely unload, then I can eliminate some problems. (Although, that now adds 1 more function that the End user may not understand, but I will live with it)

        For now that is .....
        Engineer's Motto: If it aint broke take it apart and fix it

        "If at 1st you don't succeed... call it version 1.0"

        "Half of Programming is coding"....."The other 90% is DEBUGGING"

        "Document my code????" .... "WHYYY??? do you think they call it CODE? "

        Comment


        • #5
          but the problem is LibMain with the %DLL_PROCESS_DETACH is what kicks everything off, but it can not kick off if the function is not fired until after I physically stop any tight loop function.
          Of course not if they are running in the same thread....but you seem to have an inspiration...


          maybe if I can thread certain functions
          Your real problem here is not global variables or order of call, but rather the "tight loop."

          Do a search on "Windows Events" in Source Code Forum. I have a demo in there somewhere showing exactly how to do a "tight loop" with INSTANT exit on program command.

          (I don't have my list of demos with me or I'd give you the link).
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment

          Working...
          X