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

  1. /*
  2.     EXEPTR.C -- GetExePtr example
  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 EXEPTR (for Borland C++ v3.00)
  8.                  WINIOMS EXEPTR (for Microsoft C/SDK)
  9. */
  10.  
  11. #include <windows.h>
  12. #include "winio.h"
  13.  
  14. /* undocumented function */
  15. WORD FAR PASCAL GetExePtr(HANDLE h);
  16.  
  17. main()
  18. {
  19.     char buf[128];
  20.     HANDLE hInst1, hInst2, hMod1, hMod2;
  21.  
  22.     winio_about("EXEPTR"
  23.         "\nGetExePtr example"
  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.     if ((hInst1 = WinExec("notepad.exe", SW_NORMAL)) < 32)
  30.         fail("Can't exec");
  31.     if ((hInst2 = WinExec("notepad.exe", SW_NORMAL)) < 32)
  32.         fail("Can't exec");
  33.     
  34.     hMod1 = GetExePtr(hInst1);
  35.     GetModuleFileName(hMod1, buf, 128);
  36.     printf("hInst=%04x hMod=%04x %s\n", hInst1, hMod1, buf);
  37.     
  38.     hMod2 = GetExePtr(hInst2);
  39.     GetModuleFileName(hMod2, buf, 128);
  40.     printf("hInst=%04x hMod=%04x %s\n", hInst2, hMod2, buf);
  41.     
  42.     /* Multiple instances have same module handle */
  43.     if ((hInst1 == hInst2) || (hMod1 != hMod2))
  44.         fail("Something strange!");
  45.     
  46.     return 0;
  47. }
  48.  
  49.