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.

247 lines
7.5 KiB

  1. #ifndef _INC_MLUISUPP
  2. #define _INC_MLUISUPP
  3. #include <shlwapi.h>
  4. #include <shlwapip.h>
  5. #ifdef __cplusplus
  6. extern "C"
  7. {
  8. #endif
  9. //+------------------------------------------------------------------
  10. // Multilang Pluggable UI support
  11. // inline functions defs (to centralize code)
  12. //+------------------------------------------------------------------
  13. #ifdef UNICODE
  14. #define MLLoadString MLLoadStringW
  15. #define MLBuildResURLWrap MLBuildResURLWrapW
  16. #else
  17. #define MLLoadString MLLoadStringA
  18. #define MLBuildResURLWrap MLBuildResURLWrapA
  19. #endif
  20. #undef ML_ID_DIALOGCALLS
  21. BOOL _PathRemoveFileSpec(LPTSTR pFile);
  22. void MLLoadResources(HINSTANCE hinstParent, LPTSTR pszLocResDll);
  23. void MLFreeResources(HINSTANCE hinstParent);
  24. int MLLoadStringA(UINT id, LPSTR sz, UINT cchMax);
  25. int MLLoadStringW(UINT id, LPWSTR sz, UINT cchMax);
  26. HINSTANCE MLGetHinst();
  27. INT_PTR MLDialogBoxWrap(HINSTANCE hInstance, LPCTSTR lpTemplateName, HWND hwndParent, DLGPROC lpDialogFunc);
  28. INT_PTR MLDialogBoxParamWrap(HINSTANCE hInstance, LPCWSTR lpTemplateName, HWND hwndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam);
  29. HWND MLCreateDialogParamWrap(HINSTANCE hInstance, LPCTSTR lpTemplateName, HWND hwndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam);
  30. BOOL MLEndDialogWrap(HWND hDlg, INT_PTR nResult);
  31. HWND MLHtmlHelpWrap(HWND hwndCaller, LPCTSTR pszFile, UINT uCommand, DWORD dwData, DWORD dwCrossCodePage);
  32. BOOL MLWinHelpWrap(HWND hwndCaller, LPCTSTR lpszHelp, UINT uCommand, DWORD dwData);
  33. HRESULT MLBuildResURLWrapA(LPSTR pszLibFile,
  34. HMODULE hModule,
  35. DWORD dwCrossCodePage,
  36. LPSTR pszResName,
  37. LPSTR pszResURL,
  38. int nBufSize,
  39. LPSTR pszParentDll);
  40. HRESULT MLBuildResURLWrapW(LPWSTR pszLibFile,
  41. HMODULE hModule,
  42. DWORD dwCrossCodePage,
  43. LPWSTR pszResName,
  44. LPWSTR pszResURL,
  45. int nBufSize,
  46. LPWSTR pszParentDll);
  47. HWND SHHtmlHelpOnDemandWrap(HWND hwndCaller, LPCTSTR pszFile, UINT uCommand, DWORD_PTR dwData, DWORD dwCrossCodePage);
  48. BOOL SHWinHelpOnDemandWrap(HWND hwndCaller, LPCTSTR lpszHelp, UINT uCommand, DWORD_PTR dwData);
  49. // MLLoadLibrary is used for loading the various localized resource libraries
  50. // Note: MLLoadLibrary is exported without a name, only an ordinal #
  51. #ifndef UNICODE
  52. #define szMLLoadLibrary 377 //TEXT("MLLoadLibraryA");
  53. #else
  54. #define szMLLoadLibrary 378 //TEXT("MLLoadLibraryW"); // for Unicode
  55. #endif
  56. #ifdef MLUI_INIT
  57. typedef HINSTANCE (STDAPICALLTYPE *PFNMLLOADLIBARY)(LPCSTR lpLibFileName, HMODULE hModule, DWORD dwCrossCodePage);
  58. static const char c_szShlwapiDll[] = "shlwapi.dll";
  59. struct tagMLUI_INFO
  60. {
  61. HINSTANCE hinstLocRes;
  62. ULONG ulRefs;
  63. BOOL fMLEnabled;
  64. } g_mluiInfo = { NULL, 0 , FALSE };
  65. static HINSTANCE LoadLangDll(HINSTANCE hInstCaller, LPCSTR szDllName)
  66. {
  67. char szPath[MAX_PATH];
  68. HINSTANCE hinstShlwapi;
  69. PFNMLLOADLIBARY pfn;
  70. DWORD dwVerInfoSize, dwVerHnd;
  71. int iEnd;
  72. LPSTR lpInfo;
  73. HINSTANCE hInst = NULL;
  74. UINT uLen;
  75. VS_FIXEDFILEINFO *pinfo;
  76. hinstShlwapi = LoadLibrary(c_szShlwapiDll);
  77. if (hinstShlwapi != NULL)
  78. {
  79. if (GetModuleFileName(hinstShlwapi, szPath, ARRAYSIZE(szPath)))
  80. {
  81. if (dwVerInfoSize = GetFileVersionInfoSize(szPath, &dwVerHnd))
  82. {
  83. if (MemAlloc((void **)&lpInfo, dwVerInfoSize))
  84. {
  85. if (GetFileVersionInfo(szPath, dwVerHnd, dwVerInfoSize, lpInfo))
  86. {
  87. if (VerQueryValue(lpInfo, "\\", (LPVOID *)&pinfo, &uLen) &&
  88. uLen == sizeof(VS_FIXEDFILEINFO))
  89. {
  90. if (pinfo->dwProductVersionMS >= 0x00050000)
  91. {
  92. pfn = (PFNMLLOADLIBARY)GetProcAddress(hinstShlwapi, MAKEINTRESOURCE(377));
  93. if (pfn != NULL)
  94. hInst = pfn(szDllName, hInstCaller, 0);
  95. }
  96. }
  97. }
  98. MemFree(lpInfo);
  99. }
  100. }
  101. }
  102. FreeLibrary(hinstShlwapi);
  103. }
  104. if ((NULL == hInst) && (GetModuleFileName(hInstCaller, szPath, ARRAYSIZE(szPath))))
  105. {
  106. _PathRemoveFileSpec(szPath);
  107. iEnd = lstrlen(szPath);
  108. szPath[iEnd++] = '\\';
  109. lstrcpyn(&szPath[iEnd], szDllName, ARRAYSIZE(szPath)-iEnd);
  110. hInst = LoadLibrary(szPath);
  111. }
  112. AssertSz(hInst, "Failed to LoadLibrary Lang Dll");
  113. return(hInst);
  114. }
  115. void
  116. MLLoadResources(HINSTANCE hinstParent, LPTSTR pszLocResDll)
  117. {
  118. if (g_mluiInfo.hinstLocRes == NULL)
  119. {
  120. // find out whether ML is enabled or not
  121. #ifdef MLUI_SUPPORT
  122. g_mluiInfo.fMLEnabled = TRUE;
  123. #else
  124. g_mluiInfo.fMLEnabled = FALSE;
  125. #endif
  126. if (g_mluiInfo.fMLEnabled)
  127. {
  128. g_mluiInfo.ulRefs++;
  129. // g_mluiInfo.hinstLocRes = lpfnMLLoadLibrary(pszLocResDll, hinstParent, ML_CROSSCODEPAGE);
  130. g_mluiInfo.hinstLocRes = LoadLangDll(hinstParent, pszLocResDll);
  131. }
  132. else
  133. {
  134. g_mluiInfo.hinstLocRes = hinstParent;
  135. }
  136. }
  137. }
  138. void
  139. MLFreeResources(HINSTANCE hinstParent)
  140. {
  141. g_mluiInfo.ulRefs--;
  142. if (g_mluiInfo.hinstLocRes != NULL &&
  143. g_mluiInfo.hinstLocRes != hinstParent &&
  144. g_mluiInfo.ulRefs == 0 )
  145. {
  146. FreeLibrary(g_mluiInfo.hinstLocRes);
  147. g_mluiInfo.hinstLocRes = NULL;
  148. }
  149. }
  150. int
  151. MLLoadStringA(UINT id, LPSTR sz, UINT cchMax)
  152. {
  153. return LoadStringA(g_mluiInfo.hinstLocRes, id, sz, cchMax);
  154. }
  155. int
  156. MLLoadStringW(UINT id, LPWSTR sz, UINT cchMax)
  157. {
  158. return LoadStringW(g_mluiInfo.hinstLocRes, id, sz, cchMax);
  159. // return LoadStringWrapW(g_mluiInfo.hinstLocRes, id, sz, cchMax);
  160. }
  161. HINSTANCE
  162. MLGetHinst()
  163. {
  164. return g_mluiInfo.hinstLocRes;
  165. }
  166. INT_PTR
  167. MLDialogBoxParamWrap(HINSTANCE hInstance,
  168. LPCWSTR lpTemplateName,
  169. HWND hwndParent,
  170. DLGPROC lpDialogFunc,
  171. LPARAM dwInitParam)
  172. {
  173. INT_PTR nRet;
  174. #ifdef ML_ID_DIALOGCALLS
  175. {
  176. nRet = MLDialogBoxParam(hInstance,
  177. (LPWSTR)lpTemplateName,
  178. hwndParent,
  179. lpDialogFunc,
  180. dwInitParam);
  181. }
  182. #else
  183. {
  184. nRet = DialogBoxParamWrapW(hInstance,
  185. lpTemplateName,
  186. hwndParent,
  187. lpDialogFunc,
  188. dwInitParam);
  189. }
  190. #endif
  191. return nRet;
  192. }
  193. BOOL
  194. MLEndDialogWrap(HWND hDlg, INT_PTR nResult)
  195. {
  196. BOOL fRet;
  197. #ifdef ML_ID_DIALOGCALLS
  198. {
  199. fRet = MLEndDialog(hDlg, nResult);
  200. }
  201. #else
  202. {
  203. fRet = EndDialog(hDlg, nResult);
  204. }
  205. #endif
  206. return fRet;
  207. }
  208. #endif // MLUI_INIT
  209. #ifdef __cplusplus
  210. };
  211. #endif
  212. #endif // _INC_MLUISUPP