home *** CD-ROM | disk | FTP | other *** search
- /*
- MODWALK.C -- Lists Windows modules
-
- From Chapter 5 of "Undocumented Windows" (Addison-Wesley 1992)
- by Andrew Schulman, Dave Maxey and Matt Pietrek
-
- Build using: WINIOBC MODWALK (for Borland C++ v3.00)
- WINIOMS MODWALK (for Microsoft C/SDK)
- */
-
- #include <windows.h>
- #include <dos.h>
- #include "winio.h"
-
- /* GetModuleHandle is documented, but only with WORD retval */
- DWORD (FAR PASCAL *GetModuleHandleD)(LPSTR lpModName);
-
- main()
- {
- extern WORD __hInst;
- DWORD dwMod;
- HWND hwnd;
- WORD wFirstMod, wNextMod;
- WORD wNumMods;
- WORD wThisMod;
-
- winio_about("MODWALK"
- "\nLists Windows modules"
- "\n\nFrom Chapter 5 of"
- "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
- "\nby Andrew Schulman, David Maxey and Matt Pietrek"
- );
-
- GetModuleHandleD = GetModuleHandle;
-
- dwMod = GetModuleHandleD("KERNEL");
- wFirstMod = HIWORD(dwMod); // get base of module linked list
- wNextMod = wFirstMod;
- wNumMods = 0;
- wThisMod = GetModuleHandle(MK_FP(0, __hInst)); // same as GetExePtr
- hwnd = winio_current();
- winio_setpaint(hwnd,FALSE); // so we don't yield while walking mod list!
- for (;;) // walk linked list
- {
- /*
- For an explanation of offsets 0 and 6, see the description
- of the Module Table data structure
- */
- char filename[128];
- BYTE far *fpMod = MK_FP(wNextMod, 0);
- if (fpMod[0] != 'N' || fpMod[1] != 'E') // check 'NE' signature
- fail("Not a module!");
- GetModuleFileName(wNextMod, filename, 128);
- printf("%04x %s", wNextMod, filename);
- if (wNextMod == wThisMod)
- printf(" <== this module");
- printf("\n");
- wNumMods++;
- /* Get the handle of the next Mod from offset 6 in the ModTbl */
- wNextMod = *((WORD far *) MK_FP(wNextMod, 6));
- if (wNextMod == 0)
- break;
- }
- winio_setpaint(hwnd,TRUE);
- printf("%d modules\n", wNumMods);
- return 0;
- }
-
-