差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

Both sides previous revision 前次修改
下次修改
前次修改
cpp:dll:windows:messageresourcefile [2015/05/29 15:11]
tony
cpp:dll:windows:messageresourcefile [2023/06/25 09:48] (目前版本)
行 4: 行 4:
 一般應用程式在發送NT Event Log後,很可能會在EventLogViewer中,出現Event ID找不到對應描述的問題。\\ 一般應用程式在發送NT Event Log後,很可能會在EventLogViewer中,出現Event ID找不到對應描述的問題。\\
 {{:​cpp:​dll:​windows:​eventlog_cant_find_desc.png|}}\\ {{:​cpp:​dll:​windows:​eventlog_cant_find_desc.png|}}\\
-這是因為EventLog Viewer載入以下Registry中EventMessageFile所帶的ResourceFile內容:​+這是因為EventLog Viewer載入以下Registry中EventMessageFile所帶的ResourceFile內容:​
 <code bash> <code bash>
 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\test-app HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\test-app
行 13: 行 13:
 其中EventMessageFile所參考到的,可能會是一個.exe或.dll。而內容根本來源是[[https://​msdn.microsoft.com/​en-us/​library/​windows/​desktop/​dd996906(v=vs.85).aspx|Message Text File]],是在編譯器連結期間,將Message Text File所產生的resource file給連結到.exe或.dll中。而我平常都是開發Java APP,所以我選擇產生一個專門描述Event的DLL來解決這個問題。接下來將教大家如何做到這件事情。 其中EventMessageFile所參考到的,可能會是一個.exe或.dll。而內容根本來源是[[https://​msdn.microsoft.com/​en-us/​library/​windows/​desktop/​dd996906(v=vs.85).aspx|Message Text File]],是在編譯器連結期間,將Message Text File所產生的resource file給連結到.exe或.dll中。而我平常都是開發Java APP,所以我選擇產生一個專門描述Event的DLL來解決這個問題。接下來將教大家如何做到這件事情。
 ===== How to? ===== ===== How to? =====
 +==== 建立一個Win32 DLL Project ====
 +首先選擇建立一個Win32 Project。Application type選擇dll,且將additional option選為empty project。
 +==== 新增一個Version Resource ====
 +在resource files上點擊右鍵新增resource。\\
 +{{:​cpp:​dll:​windows:​add_version_resource.png|}}
 +==== 新增Message Text File ====
 +將寫好的Messasge Text File給拖到Resource files中,至於內容怎寫可以參考:​ [[https://​msdn.microsoft.com/​en-us/​library/​windows/​desktop/​dd996906%28v=vs.85%29.aspx|link]]。\\
 +{{:​cpp:​dll:​windows:​mc_file.png|}}\\
 +==== 修改建置設定 ====
 +1. 因為不是一般的DLL程式,並沒有DLL ENTRY。所以要在Linker>​Command Line>​Additional options中加入/​NOENTRY。\\
 +2. 在編譯所需要的相關資源前,必須先編譯Message Text File。我們使用Pre-Build Event:\\
 +{{:​cpp:​dll:​windows:​buildconfig_resourcedll.png|}}
 +<code bash>
 +mkdir "​res"​ & mc.exe -A "​messages.mc"​ -r "​res"​
 +</​code>​
 +3. 將res資料夾加到編譯Resource中,要在Resource>​General>​Additional Include Directories中加入res。
 +==== 修改resource.h ====
 +加入#​include "​res/​messages.rc"​,messages.rc為執行Pre-Build Event後所產生出來的東西。
 +==== 執行建置 ====
 +相信妳已經建置成功了,如果還不成功就下載{{:​cpp:​dll:​windows:​resourcedll.zip|我這包}}去試試吧!
  
 ===== Reference ===== ===== Reference =====
   * [[https://​msdn.microsoft.com/​en-us/​library/​windows/​desktop/​dd996906(v=vs.85).aspx|Message Text File]]   * [[https://​msdn.microsoft.com/​en-us/​library/​windows/​desktop/​dd996906(v=vs.85).aspx|Message Text File]]
 +  * [[http://​www.codeproject.com/​Articles/​4166/​Using-MC-exe-message-resources-and-the-NT-event-lo|Using-MC-exe-message-resources-and-the-NT-event-lo]]