c++ 获取当前程序的主模块句柄

  char text[2014];
  GetModuleBaseNameA(GetCurrentProcess(), 0, text, 1024);
  HMODULE hModule = GetModuleHandleA(text);
  HMODULE hModule = GetModuleHandleA(NULL);
  HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, GetCurrentProcessId());
  if (hSnap != INVALID_HANDLE_VALUE)
  {
    MODULEENTRY32 me;
    me.dwSize = sizeof(me);
    if (Module32First(hSnap, &me))
    {
      printf("%ls: %x\n", me.szModule, me.hModule);
    }
  }
  CloseHandle(hSnap);
posted @ 2020-09-12 11:38  Ajanuw  阅读(1410)  评论(0编辑  收藏  举报