home *** CD-ROM | disk | FTP | other *** search
- /*
- EXEPTR.C -- GetExePtr example
-
- From Chapter 5 of "Undocumented Windows" (Addison-Wesley 1992)
- by Andrew Schulman, Dave Maxey and Matt Pietrek
-
- Build using: WINIOBC EXEPTR (for Borland C++ v3.00)
- WINIOMS EXEPTR (for Microsoft C/SDK)
- */
-
- #include <windows.h>
- #include "winio.h"
-
- /* undocumented function */
- WORD FAR PASCAL GetExePtr(HANDLE h);
-
- main()
- {
- char buf[128];
- HANDLE hInst1, hInst2, hMod1, hMod2;
-
- winio_about("EXEPTR"
- "\nGetExePtr example"
- "\n\nFrom Chapter 5 of"
- "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
- "\nby Andrew Schulman, David Maxey and Matt Pietrek"
- );
-
- if ((hInst1 = WinExec("notepad.exe", SW_NORMAL)) < 32)
- fail("Can't exec");
- if ((hInst2 = WinExec("notepad.exe", SW_NORMAL)) < 32)
- fail("Can't exec");
-
- hMod1 = GetExePtr(hInst1);
- GetModuleFileName(hMod1, buf, 128);
- printf("hInst=%04x hMod=%04x %s\n", hInst1, hMod1, buf);
-
- hMod2 = GetExePtr(hInst2);
- GetModuleFileName(hMod2, buf, 128);
- printf("hInst=%04x hMod=%04x %s\n", hInst2, hMod2, buf);
-
- /* Multiple instances have same module handle */
- if ((hInst1 == hInst2) || (hMod1 != hMod2))
- fail("Something strange!");
-
- return 0;
- }
-
-