home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / mswindo / programm / misc / 4249 < prev    next >
Encoding:
Internet Message Format  |  1992-12-15  |  2.2 KB

  1. Path: sparky!uunet!lax.pe-nelson.com!lax!twbrown
  2. From: twbrown@PE-Nelson.COM (Tom W. Brown)
  3. Newsgroups: comp.os.ms-windows.programmer.misc
  4. Subject: Re: DLL-question
  5. Keywords: Alloc, Peekmessage
  6. Message-ID: <713@lax.lax.pe-nelson.com>
  7. Date: 15 Dec 92 17:48:09 GMT
  8. References: <2914@media03.UUCP>
  9. Sender: news@lax.pe-nelson.com
  10. Organization: PE-Nelson
  11. Lines: 49
  12.  
  13. In article <2914@media03.UUCP>, rla@media03.UUCP (Raymond van der Laan) writes:
  14. |> Is this possible in a DLL:
  15. |> 
  16. |>     ... x;
  17. |>     ... y;
  18. |> 
  19. |>     f1 ()
  20. |>     {
  21. |>         y = GlobalAlloc(...);
  22. |>         x = GlobalLock(y);
  23. |>         PeekMessage()
  24. |>         if ours then memcpy(x,...,...);
  25. |>         else Translate & DispatchMessage
  26. |>         ...
  27. |>     }
  28. |> 
  29. |>     f2 (a)
  30. |>     {
  31. |>         memcpy(a, x, ...);
  32. |>         GlobalFree(y);      <-------------\
  33. |>     }                                     |
  34. |>                                           |
  35. |> The caller calls f1, then f2.             |
  36.                                              |
  37. Yes, but some considerations:                |
  38.                                              |
  39.   - Don't forget the GlobalUnlock().  -------/
  40.  
  41.   - If x and y are global variables for the DLL then f1() and f2() are
  42.     not reentrant.  Consider what happens if you have two applications
  43.     using your DLL and the translate/dispatch within f1() for app1 causes
  44.     app2 to call f1().
  45.  
  46.     This is probably not a concern for you, but if it is then you will
  47.     want to take some steps to either prevent reentrancy, provide
  48.     some form of mutual exclusion in f1() and f2(), or allow x and y
  49.     to be instance variables for each application using the DLL.
  50.  
  51.   - The above example is clear enough in what it does, but not at all
  52.     clear is why you are considering this.  What is happening in your
  53.     application that requires this functionality in a DLL?
  54.  
  55.  
  56.  
  57. ----------------------------------------------------------------------------
  58. Tom Brown               |  "She turned me into a newt...
  59. PE Nelson Systems       |                                  ... I got better"
  60. twbrown@pe-nelson.com   |                    Monty Python and the Holy Grail
  61. ----------------------------------------------------------------------------
  62.