Utility.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "StdAfx.h"
  2. #include "Utility.h"
  3. namespace Utility
  4. {
  5. // 当前DLL模块句柄;
  6. HMODULE g_hDLLModule = NULL;
  7. // 当前DLL内部工作者线程句柄;
  8. HANDLE hWorkThreadProc = NULL;
  9. // 当前DLL所在路径;
  10. TCHAR g_szCurModulePath[MAX_PATH] = {0};
  11. // 管道实例;
  12. CPipeClient *g_pPipeClient = NULL;
  13. // 配置文件名称;
  14. TCHAR g_szConfigFile[MAX_PATH] = {0};
  15. // 配置文件内容;
  16. CFG_CTX g_cfgCtx;
  17. //////////////////////////////////////////////////////////////////////////
  18. // 全局函数;
  19. // 获取配置文件内容;
  20. void GetConfigContent()
  21. {
  22. // 获取dll的目录;
  23. TCHAR szDrive[MAX_PATH] = { 0 };
  24. TCHAR szDir[MAX_PATH] = { 0 };
  25. TCHAR szExt[MAX_PATH] = { 0 };
  26. TCHAR szFna[MAX_PATH] = { 0 };
  27. ::GetModuleFileName(g_hDLLModule, g_szCurModulePath, sizeof(g_szCurModulePath) / sizeof(TCHAR));
  28. _tsplitpath_s(g_szCurModulePath, szDrive, szDir, szFna, szExt);
  29. _tcscpy_s(g_szCurModulePath, szDrive);
  30. _tcscat_s(g_szCurModulePath, szDir);
  31. // 设置配置文件;
  32. _stprintf_s(g_szConfigFile, _T("%s%s"), g_szCurModulePath, _T("Assist.ini"));
  33. // 读取配置文件;
  34. TCHAR szValue[MAX_PATH] = {0};
  35. GetPrivateProfileString(_T("Windows"), _T("Title"), _T(""), g_cfgCtx.szWindowTitel, MAX_PATH, g_szConfigFile);
  36. GetPrivateProfileString(_T("Pipe"), _T("Name"), _T("Assist"), szValue, MAX_PATH, g_szConfigFile);
  37. _stprintf_s(g_cfgCtx.szPipeName, _T("\\\\.\\pipe\\%s"), szValue);
  38. GetPrivateProfileString(_T("Process"), _T("Name"), _T("Game.exe"), g_cfgCtx.szWndProcessName, MAX_PATH, g_szConfigFile);
  39. }
  40. void FreeLibraryAndExit()
  41. {
  42. if ( g_hDLLModule )
  43. FreeLibraryAndExitThread(g_hDLLModule, 0);
  44. }
  45. };