Leaked source code of windows server 2003
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.

150 lines
4.1 KiB

  1. // File: intlutil.cpp
  2. #include <precomp.h>
  3. #include <shlwapi.h>
  4. #include <confreg.h>
  5. #include <regentry.h>
  6. #include <oprahcom.h>
  7. #include "intlutil.h"
  8. static const TCHAR g_szSHLWAPI[] = TEXT("shlwapi.dll");
  9. const LPCSTR c_szMLLoadLibraryA = (LPCSTR)377;
  10. const LPCSTR c_szMLLoadLibraryW = (LPCSTR)378;
  11. const LPCSTR c_szDllGetVersion = "DllGetVersion";
  12. const LPCSTR c_szPathRemoveFileSpecA = "PathRemoveFileSpecA";
  13. const LPCSTR c_szPathRemoveFileSpecW = "PathRemoveFileSpecW";
  14. const DWORD SHLWAPI_MAJOR_VERSION = 5;
  15. const DWORD SHLWAPI_MINOR_VERSION = 0;
  16. const DWORD SHLWAPI_BUILD_NUMBER = 1000;
  17. typedef HINSTANCE (STDAPICALLTYPE * PFN_MLLoadLibraryA)(LPCSTR lpLibFileName, HMODULE hModule, DWORD dwCrossCodePage);
  18. typedef HINSTANCE (STDAPICALLTYPE * PFN_MLLoadLibraryW)(LPCWSTR lpLibFileName, HMODULE hModule, DWORD dwCrossCodePage);
  19. typedef BOOL (STDAPICALLTYPE * PFN_PathRemoveFileSpecA)(LPSTR pszPath);
  20. typedef BOOL (STDAPICALLTYPE * PFN_PathRemoveFileSpecW)(LPWSTR pszPath);
  21. #ifdef UNICODE
  22. #define c_szMLLoadLibrary c_szMLLoadLibraryW
  23. #define PFN_MLLoadLibrary PFN_MLLoadLibraryW
  24. #define c_szPathRemoveFileSpec c_szPathRemoveFileSpecW
  25. #define PFN_PathRemoveFileSpec PFN_PathRemoveFileSpecW
  26. #else
  27. #define c_szMLLoadLibrary c_szMLLoadLibraryA
  28. #define PFN_MLLoadLibrary PFN_MLLoadLibraryA
  29. #define c_szPathRemoveFileSpec c_szPathRemoveFileSpecA
  30. #define PFN_PathRemoveFileSpec PFN_PathRemoveFileSpecA
  31. #endif
  32. BOOL g_fUseMLHelp = FALSE;
  33. #define SIZEOF_ARRAY(ar) (sizeof(ar)/sizeof((ar)[0]))
  34. inline BOOL CheckShlwapiVersion(HINSTANCE hShlwapiDll)
  35. {
  36. BOOL fVersionOk = FALSE;
  37. DLLGETVERSIONPROC pfnDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hShlwapiDll, c_szDllGetVersion);
  38. if(pfnDllGetVersion)
  39. {
  40. DLLVERSIONINFO dvi;
  41. HRESULT hr;
  42. ZeroMemory(&dvi, sizeof(dvi));
  43. dvi.cbSize = sizeof(dvi);
  44. hr = (*pfnDllGetVersion)(&dvi);
  45. if (SUCCEEDED(hr))
  46. {
  47. if (dvi.dwMajorVersion > SHLWAPI_MAJOR_VERSION)
  48. {
  49. fVersionOk = TRUE;
  50. }
  51. else if (dvi.dwMajorVersion == SHLWAPI_MAJOR_VERSION)
  52. {
  53. if (dvi.dwMinorVersion > SHLWAPI_MINOR_VERSION)
  54. {
  55. fVersionOk = TRUE;
  56. }
  57. else if (dvi.dwMinorVersion == SHLWAPI_MINOR_VERSION)
  58. {
  59. if (dvi.dwBuildNumber >= SHLWAPI_BUILD_NUMBER)
  60. {
  61. fVersionOk = TRUE;
  62. }
  63. }
  64. }
  65. }
  66. }
  67. return fVersionOk;
  68. }
  69. /* L O A D N M R E S */
  70. /*-------------------------------------------------------------------------
  71. %%Function: LoadNmRes
  72. Load the international resource dll.
  73. -------------------------------------------------------------------------*/
  74. HINSTANCE NMINTERNAL LoadNmRes(LPCTSTR pszFile)
  75. {
  76. HINSTANCE hInst = NULL;
  77. if (NULL == pszFile)
  78. {
  79. // Use the default file name
  80. pszFile = TEXT("nmres.dll");
  81. }
  82. RegEntry reConf(CONFERENCING_KEY, HKEY_LOCAL_MACHINE);
  83. if (!reConf.GetNumber(REGVAL_DISABLE_PLUGGABLE_UI, 0))
  84. {
  85. HINSTANCE hLib = NmLoadLibrary(g_szSHLWAPI,TRUE);
  86. if (hLib)
  87. {
  88. if (CheckShlwapiVersion(hLib))
  89. {
  90. PFN_MLLoadLibrary pfnMLLoadLibrary =
  91. (PFN_MLLoadLibrary)GetProcAddress(hLib, c_szMLLoadLibrary);
  92. PFN_PathRemoveFileSpec pfnPathRemoveFileSpec =
  93. (PFN_PathRemoveFileSpec)GetProcAddress(hLib, c_szPathRemoveFileSpec);
  94. if ((NULL != pfnMLLoadLibrary) && (NULL != pfnPathRemoveFileSpec))
  95. {
  96. hInst = pfnMLLoadLibrary(pszFile, GetModuleHandle(NULL), 0);
  97. if (hInst)
  98. {
  99. // check to see if the Resource DLL was loaded from the ML Satellite
  100. // if not, don't use ML for Help
  101. TCHAR szThis[MAX_PATH];
  102. TCHAR szResource[MAX_PATH];
  103. if (GetModuleFileName(NULL, szThis, SIZEOF_ARRAY(szThis)) &&
  104. pfnPathRemoveFileSpec(szThis) &&
  105. GetModuleFileName(hInst, szResource, SIZEOF_ARRAY(szThis)) &&
  106. pfnPathRemoveFileSpec(szResource) &&
  107. (0 != lstrcmp(szThis, szResource)) )
  108. {
  109. g_fUseMLHelp = TRUE;
  110. }
  111. }
  112. }
  113. }
  114. FreeLibrary(hLib);
  115. }
  116. }
  117. if (!hInst)
  118. {
  119. hInst = NmLoadLibrary(pszFile,FALSE);
  120. if (NULL == hInst)
  121. {
  122. ERROR_OUT(("Unable to load resource file [%s]", pszFile));
  123. }
  124. }
  125. return hInst;
  126. }