imgwalk.c

来自「一本已经绝版的好书」· C语言 代码 · 共 64 行

C
64
字号
/************************************************************
Module name: ImgWalk.C
Notices: Copyright (c) 1995-1997 Jeffrey Richter
************************************************************/


#include "..\CmnHdr.H"                  /* See Appendix C. */
#include <windows.h>
#include <stdio.h>
#include <tchar.h>


/////////////////////////////////////////////////////////////


BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, 
   LPVOID lpvReserved) {

   TCHAR szBuf[MAX_PATH * 30], szModName[MAX_PATH];

   if (fdwReason == DLL_PROCESS_ATTACH) {
      LPBYTE lp = NULL;
      MEMORY_BASIC_INFORMATION mbi;
      int nLen;
      szBuf[0] = 0;
      szBuf[1] = 0;

      while (VirtualQuery(lp, &mbi, sizeof(mbi))
         == sizeof(mbi)) {
         if (mbi.State == MEM_FREE)
            mbi.AllocationBase = mbi.BaseAddress;

         if ((mbi.AllocationBase == hinstDll) ||
             (mbi.AllocationBase != mbi.BaseAddress) ||
             (mbi.AllocationBase == NULL)) {
             // Do not add the module name to the list
             // if any of the following is true:
             // 1. If this region contains this DLL
             // 2. If this block is NOT the beginning of
             //    a region
             // 3. If the address is NULL
            nLen = 0;
         } else {
            nLen = GetModuleFileName(
               (HINSTANCE) mbi.AllocationBase,
               szModName, chDIMOF(szModName));
         }

         if (nLen > 0) {
            _stprintf(_tcschr(szBuf, 0), __TEXT("\n%08X-%s"),
               mbi.AllocationBase, szModName);
         }

         lp += mbi.RegionSize;
      }

      chMB(&szBuf[1]);
   }
   return(TRUE);
}


//////////////////////// End Of File ////////////////////////

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?