home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_12 / 2n12012a < prev    next >
Text File  |  1991-10-30  |  3KB  |  96 lines

  1. /*****************************************************/
  2. /* mlefix.c                                          */
  3. /* -- Program to fix the leaky MLE bug.              */
  4. /*****************************************************/
  5.  
  6. #define NOCOMM
  7. #include <windows.h>
  8. #include "win.h"
  9.  
  10. HANDLE  hmemUser;
  11. FARPROC lpfnMLEFilter;
  12.  
  13. LONG    FAR PASCAL  MLEFilter(WORD, WORD, WORD, DWORD);
  14. int     FAR PASCAL  LibMain(HANDLE, WORD, WORD, LPSTR);
  15. int     FAR PASCAL  WEP(short);
  16.  
  17. int FAR PASCAL
  18. LibMain(HANDLE hins, WORD ds, WORD cbHeap, LPSTR lsz)
  19. /*****************************************************/
  20. /* -- hins      : This library's instance.           */
  21. /* -- ds        : The library's default data segment */
  22. /* -- cbHeap    : Size of out local heap.            */
  23. /* -- lsz       : Command line invoked with.         */
  24. /*****************************************************/
  25.     {
  26.     WORD        wVersion    = GetVersion();
  27.     WNDCLASS    wcs;
  28.  
  29.     /* Only need to fix this bug for version 3.0. */
  30.     if (LOBYTE(wVersion) != 3 || HIBYTE(wVersion) != 0)
  31.         return FALSE;
  32.  
  33.     /* Get USER's default data segment. */
  34.     if ((hmemUser = LoadLibrary("user.exe")) == 0)
  35.         return FALSE;
  36.  
  37.     /* Superclass the edit class. */
  38.     GetClassInfo(NULL, "edit", &wcs);
  39.     UnregisterClass("edit", NULL);
  40.     lpfnMLEFilter = (FARPROC)wcs.lpfnWndProc;
  41.     wcs.lpfnWndProc = MLEFilter;
  42.     RegisterClass(&wcs);    /* This better work! */
  43.  
  44.     return TRUE;
  45.     }
  46.  
  47. int FAR PASCAL
  48. WEP(short wCode)
  49. /*****************************************************/
  50. /* -- The usual do-nothing stub.                     */
  51. /*****************************************************/
  52.     {
  53.     return FALSE;
  54.     }
  55.  
  56. LONG FAR PASCAL
  57. MLEFilter(WORD hwnd, WORD wm, WORD mp1, DWORD lmp1)
  58. /*****************************************************/
  59. /* -- Superclasser for MLE's.                        */
  60. /* -- hwnd      : Main window.                       */
  61. /* -- wm        : Message type.                      */
  62. /* -- mp1, mp2  : Message parameters.                */
  63. /*****************************************************/
  64.     {
  65.     LONG    lVal;
  66.  
  67.     lVal = CallWindowProc(lpfnMLEFilter, hwnd, wm, mp1,
  68.         lmp1);
  69.  
  70.     if (wm == WM_NCCREATE &&
  71.         (GetWindowLong(hwnd, GWL_STYLE) &
  72.             (WS_VSCROLL | WS_HSCROLL)))
  73.         {
  74.         WORD    dsUser  = HIWORD(GlobalLock(hmemUser));
  75.         WORD    dsLocal;
  76.  
  77.         _asm    mov dsLocal, ds;    /* Save ds. */
  78.         _asm    mov ds, dsUser;     /* Get USER ds. */
  79.  
  80.         /* Free dangling USER heap memory. */
  81.         if (((WND *)hwnd)->unknown4 != 0)
  82.             {
  83.             LocalFree(((WND *)hwnd)->unknown4);
  84.             ((WND *)hwnd)->unknown4 = 0;
  85.             }
  86.  
  87.         _asm    mov ds, dsLocal;    /* Restore ds. */
  88.  
  89.         /* In case of REAL mode. */
  90.         GlobalUnlock(hmemUser);
  91.         }
  92.  
  93.     return lVal;
  94.     }
  95.  
  96.