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.

163 lines
4.3 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. inline BOOL CheckShlwapiVersion(HINSTANCE hShlwapiDll)
  34. {
  35. BOOL fVersionOk = FALSE;
  36. DLLGETVERSIONPROC pfnDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hShlwapiDll, c_szDllGetVersion);
  37. if(pfnDllGetVersion)
  38. {
  39. DLLVERSIONINFO dvi;
  40. HRESULT hr;
  41. ZeroMemory(&dvi, sizeof(dvi));
  42. dvi.cbSize = sizeof(dvi);
  43. hr = (*pfnDllGetVersion)(&dvi);
  44. if (SUCCEEDED(hr))
  45. {
  46. if (dvi.dwMajorVersion > SHLWAPI_MAJOR_VERSION)
  47. {
  48. fVersionOk = TRUE;
  49. }
  50. else if (dvi.dwMajorVersion == SHLWAPI_MAJOR_VERSION)
  51. {
  52. if (dvi.dwMinorVersion > SHLWAPI_MINOR_VERSION)
  53. {
  54. fVersionOk = TRUE;
  55. }
  56. else if (dvi.dwMinorVersion == SHLWAPI_MINOR_VERSION)
  57. {
  58. if (dvi.dwBuildNumber >= SHLWAPI_BUILD_NUMBER)
  59. {
  60. fVersionOk = TRUE;
  61. }
  62. }
  63. }
  64. }
  65. }
  66. return fVersionOk;
  67. }
  68. /* L O A D N M R E S */
  69. /*-------------------------------------------------------------------------
  70. %%Function: LoadNmRes
  71. Load the international resource dll.
  72. -------------------------------------------------------------------------*/
  73. HINSTANCE NMINTERNAL LoadNmRes(LPCTSTR pszFile)
  74. {
  75. HINSTANCE hInst = NULL;
  76. if (NULL == pszFile)
  77. {
  78. // Use the default file name
  79. pszFile = TEXT("nmres.dll");
  80. }
  81. RegEntry reConf(CONFERENCING_KEY, HKEY_LOCAL_MACHINE);
  82. if (!reConf.GetNumber(REGVAL_DISABLE_PLUGGABLE_UI, 0))
  83. {
  84. HINSTANCE hLib = LoadLibrary(g_szSHLWAPI);
  85. if (hLib)
  86. {
  87. if (CheckShlwapiVersion(hLib))
  88. {
  89. PFN_MLLoadLibrary pfnMLLoadLibrary =
  90. (PFN_MLLoadLibrary)GetProcAddress(hLib, c_szMLLoadLibrary);
  91. PFN_PathRemoveFileSpec pfnPathRemoveFileSpec =
  92. (PFN_PathRemoveFileSpec)GetProcAddress(hLib, c_szPathRemoveFileSpec);
  93. if ((NULL != pfnMLLoadLibrary) && (NULL != pfnPathRemoveFileSpec))
  94. {
  95. hInst = pfnMLLoadLibrary(pszFile, GetModuleHandle(NULL), 0);
  96. if (hInst)
  97. {
  98. // check to see if the Resource DLL was loaded from the ML Satellite
  99. // if not, don't use ML for Help
  100. TCHAR szThis[MAX_PATH];
  101. TCHAR szResource[MAX_PATH];
  102. if (GetModuleFileName(NULL, szThis, CCHMAX(szThis)) &&
  103. pfnPathRemoveFileSpec(szThis) &&
  104. GetModuleFileName(hInst, szResource, CCHMAX(szThis)) &&
  105. pfnPathRemoveFileSpec(szResource) &&
  106. (0 != lstrcmp(szThis, szResource)) )
  107. {
  108. g_fUseMLHelp = TRUE;
  109. }
  110. }
  111. }
  112. }
  113. }
  114. }
  115. if (!hInst)
  116. {
  117. TCHAR szDll[MAX_PATH];
  118. if (GetInstallDirectory(szDll))
  119. {
  120. if ((lstrlen(pszFile) + lstrlen(szDll)) < CCHMAX(szDll))
  121. {
  122. lstrcat(szDll, pszFile);
  123. // It would be best to load the dll as a resource, unfortunately
  124. // CreateWindow and PropertySheet code fails unless this is a
  125. // real, active module handle
  126. //
  127. // hInst = LoadLibraryEx(szDll, NULL, LOAD_LIBRARY_AS_DATAFILE);
  128. //
  129. hInst = LoadLibrary(szDll);
  130. if (NULL == hInst)
  131. {
  132. ERROR_OUT(("Unable to load resource file [%s]", szDll));
  133. }
  134. }
  135. }
  136. }
  137. return hInst;
  138. }