Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
2.1 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. avrfutil.h
  5. Abstract:
  6. Common headers for app verifier utility functions - used by the exe as well as the shims
  7. Revision History:
  8. 08/26/2001 dmunsil Created.
  9. --*/
  10. #pragma once
  11. #ifndef _AVRFUTIL_H_
  12. #define _AVRFUTIL_H_
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <ntldr.h>
  17. #include <windows.h>
  18. #include <prsht.h>
  19. #include "shimdb.h"
  20. namespace ShimLib
  21. {
  22. #define AV_BREAKIN L"BreakOnLog"
  23. BOOL SaveShimSettingDWORD(
  24. LPCWSTR szShim,
  25. LPCWSTR szExe,
  26. LPCWSTR szSetting,
  27. DWORD dwSetting
  28. );
  29. DWORD GetShimSettingDWORD(
  30. LPCWSTR szShim,
  31. LPCWSTR szExe,
  32. LPCWSTR szSetting,
  33. DWORD dwDefault
  34. );
  35. BOOL SaveShimSettingString(
  36. LPCWSTR szShim,
  37. LPCWSTR szExe,
  38. LPCWSTR szSetting,
  39. LPCWSTR szValue
  40. );
  41. BOOL GetShimSettingString(
  42. LPCWSTR szShim,
  43. LPCWSTR szExe,
  44. LPCWSTR szSetting,
  45. LPWSTR szResult,
  46. DWORD dwBufferLen // in WCHARs
  47. );
  48. //
  49. // Handy macro-like name extraction utility for property sheets
  50. // NOTE: only works during WM_INITDIALOG!!!
  51. //
  52. inline LPCWSTR ExeNameFromLParam(LPARAM lParam)
  53. {
  54. if (lParam) {
  55. LPCWSTR szRet = (LPCWSTR)(((LPPROPSHEETPAGE)lParam)->lParam);
  56. if (szRet) {
  57. return szRet;
  58. }
  59. }
  60. return AVRF_DEFAULT_SETTINGS_NAME_W;
  61. }
  62. //
  63. // useful utility function for getting the current exe name during shim
  64. // startup (so it extracts the correct settings)
  65. //
  66. inline LPWSTR GetCurrentExeName(LPWSTR szName, DWORD dwChars)
  67. {
  68. HMODULE hMod = GetModuleHandle(NULL);
  69. if (!hMod) {
  70. return NULL;
  71. }
  72. WCHAR szModule[MAX_PATH];
  73. DWORD dwC = GetModuleFileNameW(hMod, szModule, MAX_PATH);
  74. if (!dwC) {
  75. return NULL;
  76. }
  77. int nLen = (int)wcslen(szModule);
  78. for (int i = nLen - 1; i != -1; --i) {
  79. if (szModule[i] == L'\\') {
  80. break;
  81. }
  82. }
  83. ++i;
  84. wcsncpy(szName, &szModule[i], dwChars);
  85. szName[dwChars - 1] = 0;
  86. return szName;
  87. }
  88. }; // end of namespace ShimLib
  89. #endif