home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l430 / 1.ddi / CHAP4.ZIP / BASEMOV2.C next >
Encoding:
C/C++ Source or Header  |  1992-06-11  |  1.8 KB  |  66 lines

  1. /*
  2.     BASEMOV2.C -- use GetSelectorBase to show segment movement
  3.     within the linear address space
  4.  
  5.     From Chapter 4 of "Undocumented Windows" (Addison Wesley 1992)
  6.     by Andrew Schulman, Dave Maxey and Matt Pietrek
  7.         
  8.     Build using: WINIOBC BASEMOV2 (for Borland C++ v3.00)
  9.                  WINIOMS BASEMOV2 (for Microsoft C/SDK)
  10. */
  11.  
  12. #include <windows.h>
  13. #include "wmhandlr.h"
  14. #include "winio.h"
  15.  
  16. /* undocumented function */
  17. DWORD FAR PASCAL GetSelectorBase(WORD sel);
  18.  
  19. static WORD code, data;
  20.  
  21. void gc(HWND hwnd, int wID)
  22. {
  23.     printf("GC(-1) = %lu\n", GlobalCompact(-1L));
  24. }
  25.  
  26. long on_time(HWND hwnd, unsigned message, WORD wParam, LONG lParam)
  27. {
  28.     static DWORD basecode, basedata;
  29.     static DWORD prevcode = -1, prevdata = -1;
  30.     
  31.     if (((basecode = GetSelectorBase(code)) != prevcode) ||
  32.         ((basedata = GetSelectorBase(data)) != prevdata))
  33.     {
  34.         printf("CS (%04x) = %08lx\tDS (%04x) = %08lx\n",
  35.             code, basecode, data, basedata);
  36.         prevcode = basecode;
  37.         prevdata = basedata;
  38.     }
  39.     return 0;
  40. }
  41.         
  42. int main()
  43. {
  44.     HWND hwnd = winio_current();
  45.     HMENU hmenu = CreateMenu();
  46.     HMENU hmenumain = winio_hmenumain(hwnd);
  47.     winio_about("BASEMOV2\nMonitors CS selector base for movement"
  48.         "\n\nFrom Chapter 4 of"
  49.         "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
  50.         "\nby Andrew Schulman, David Maxey and Matt Pietrek");
  51.     AppendMenu(hmenu, MF_STRING | MF_ENABLED, 1, "GC(-1)");
  52.     InsertMenu(hmenumain, 1, MF_STRING | MF_POPUP | MF_BYPOSITION,
  53.         hmenu, "&Test");
  54.     winio_setmenufunc(hwnd, 1, gc);
  55.     DrawMenuBar(hwnd);
  56.     
  57.     _asm mov code, cs
  58.     _asm mov data, ds
  59.     
  60.     wmhandler_set(hwnd, WM_TIMER, on_time);
  61.     if (! SetTimer(hwnd, 1, 1000, NULL)) // once a second
  62.         fail("can't create timer");
  63.     return 0;
  64. }
  65.  
  66.