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.

80 lines
2.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: uihooks.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // uihooks.cpp
  11. // Hook Function extensions for CSC UI
  12. #include "pch.h"
  13. #include "uihooks.h"
  14. #ifdef CSCUI_HOOKS
  15. // This is the registry key where we put the DLL name
  16. TCHAR const c_szUIHookKey[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\NetCache");
  17. TCHAR const c_szUIHookValue[] = TEXT("CSCUI Hook DLL");
  18. char const c_szUIHookProc[] = "CSCUIHook";
  19. typedef void (WINAPI *PFNCSCHOOK)(DWORD, LPCWSTR);
  20. static HINSTANCE g_hHookDll = NULL;
  21. static PFNCSCHOOK g_pfnCscHook = NULL;
  22. static BOOL g_bHooksInitialized = FALSE;
  23. // Checks the reg key, and sets up function pointers if necessary
  24. void CSCUIExt_InitializeHooks()
  25. {
  26. HKEY hRegKey;
  27. g_bHooksInitialized = TRUE;
  28. // Lets check if the reg key is there
  29. if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szUIHookKey, 0, KEY_READ, &hRegKey) == ERROR_SUCCESS)
  30. {
  31. TCHAR szHookDll[MAX_PATH];
  32. DWORD dwSize = sizeof(szHookDll);
  33. if(RegQueryValueEx(hRegKey, c_szUIHookValue, 0, NULL, (LPBYTE)szHookDll, &dwSize) == ERROR_SUCCESS)
  34. {
  35. g_hHookDll = LoadLibrary(szHookDll);
  36. if(g_hHookDll != NULL)
  37. g_pfnCscHook = (PFNCSCHOOK)GetProcAddress(g_hHookDll, c_szUIHookProc);
  38. }
  39. RegCloseKey(hRegKey);
  40. }
  41. }
  42. void CSCUIExt_CleanupHooks()
  43. {
  44. if(g_hHookDll)
  45. {
  46. FreeLibrary(g_hHookDll);
  47. g_hHookDll = NULL;
  48. g_pfnCscHook = NULL;
  49. }
  50. }
  51. void CSCUIExt_NotifyHook(DWORD csch, LPCTSTR psz, ...)
  52. {
  53. USES_CONVERSION;
  54. if(!g_bHooksInitialized)
  55. CSCUIExt_InitializeHooks();
  56. if(g_pfnCscHook)
  57. {
  58. LPTSTR pszMsg = NULL;
  59. va_list va;
  60. va_start(va, psz);
  61. vFormatString(&pszMsg, psz, &va);
  62. (*g_pfnCscHook)(csch, T2CW(pszMsg));
  63. LocalFreeString(&pszMsg);
  64. va_end(va);
  65. }
  66. }
  67. #endif // CSCUI_HOOKS