home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l430 / 1.ddi / CHAP5.ZIP / TESTHAND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.9 KB  |  62 lines

  1. /*
  2.     TESTHAND.C -- Test driver for HANDLES.H and HANDLES.C
  3.  
  4.     From Chapter 5 of "Undocumented Windows" (Addison-Wesley 1992)
  5.     by Andrew Schulman, Dave Maxey and Matt Pietrek
  6.  
  7.     Build using: WINIOBC TESTHAND HANDLES (for Borland C++ v3.00)
  8.                  WINIOMS TESTHAND HANDLES (for Microsoft C/SDK)
  9. */
  10.  
  11. #include <windows.h>
  12. #include <stdlib.h>
  13. #include <assert.h>
  14. #include "winio.h"
  15. #include "handles.h"
  16.  
  17. main()
  18. {
  19.     extern HANDLE __hInst;  // in ARGCARGV.C
  20.     HANDLE hTask, hModule, hModule2, hInstance, PSP;
  21.     
  22.     winio_about("TESTHAND"
  23.         "\nTest driver for HANDLES.H and HANDLES.C"
  24.         "\n\nFrom Chapter 5 of"
  25.         "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
  26.         "\nby Andrew Schulman, David Maxey and Matt Pietrek"
  27.         );
  28.     
  29.     printf("Windows %d.%02d %s mode (%s)\n",
  30.         LOBYTE(GetVersion()), HIBYTE(GetVersion()),
  31.         (GetWinFlags() & WF_STANDARD) ? "Standard" : "Enhanced",
  32.         (GetSystemMetrics(SM_DEBUG)) ? "DEBUG" : "RETAIL");
  33.     
  34.     hTask = GetCurrentTask();
  35.     printf("hTask = %04x\n", hTask);
  36.     
  37.     hInstance = HINSTANCE_FROM_HTASK(hTask);
  38.     printf("hInstance = %04x\n", hInstance);
  39.     assert(hInstance == __hInst);
  40.     
  41.     hModule = HMODULE_FROM_HTASK(hTask);
  42.     hModule2 = HMODULE_FROM_HINSTANCE(hInstance);
  43.     printf("hModule = %04x\n", hModule);
  44.     assert(hModule == hModule2);
  45.     
  46.     PSP = PSP_FROM_HTASK(hTask);
  47.     printf("PSP = %04x\n", PSP);
  48.     assert(PSP == GetCurrentPDB());
  49.     
  50.     assert(hTask_from_hInstance(hInstance) == hTask);
  51.     assert(PSP_FROM_HINSTANCE(hInstance) == PSP);
  52.     assert(hTask_from_PSP(PSP) == hTask);
  53.     assert(HINSTANCE_FROM_PSP(PSP) == hInstance);
  54.         
  55.     assert(IsValidModuleHandle(GetCurrentModule()));
  56.     assert(IsValidPSP(GetCurrentPDB()));
  57.     assert(IsValidTask(GetCurrentTask()));
  58.     
  59.     return 0;
  60. }
  61.  
  62.