如何獲得當前所在的DLL模組名稱

2021-04-07 08:26:37 字數 521 閱讀 5474

起因:

因為工作需要,寫了乙個小工具,嵌入到各個專案中(這些專案都是dll專案).然後,在這個工具可以輸出一些資訊到日誌檔案.當然,輸出資訊需要標明這些資訊來自哪個程式模組.首先,就想到了getmodulefilename,一查msdn,第乙個引數hmodule無法提供,如果提供null,只能得到建立程序的那個exe檔案。又順藤摸瓜,找到了getmodulehandle函式。然而,問題仍然存在:getmodulehandle需要乙個

忽然想到,getmodulehandleex是不是有額外的功能呢?查閱之下,大喜,於是如下獲得當前模組檔名: 

hmodule hmodule = null;

getmodulehandleex(get_module_handle_ex_flag_from_address,

(lpcstr)&getlogfile, //這是函式名,強轉

&hmodule);

dword len = getmodulefilenamea(hmodule, buffer, sizeof buffer);

如何獲得當前執行程式所在的路徑

如果是linux,看下面這些 利用proc可以獲得完整的路徑 乙個linux下的例子 include include ifndef path max define path max 1024 endif char get exe name buf rslt 0 return buf int main...

android之獲得當前連線wifi的名字

原文 android之獲得當前連線wifi的名字 wifimanager wifimgr wifimanager mactivity.getsystemservice context.wifi service int wifistate wifimgr.getwifistate wifiinfo i...

如何獲得當前執行模組在程序位址空間的位置

w winmain的hinstanceexe引數實際值是乙個記憶體基位址 系統將可執行檔案的映像載入到程序位址空間中的這個位置。例如,系統開啟可執行檔案,並將它載入到位址0x00400000,則 w winmain的hinstanceexe引數值為0x00400000.為了知道乙個可執行檔案或dll...