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.

253 lines
6.8 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. // copied over from shell\inc\mluisupp.h with unneeded stuff removed.
  13. //+------------------------------------------------------------------
  14. #ifdef UNICODE
  15. #define MLLoadString MLLoadStringW
  16. #define MLLoadShellLangString MLLoadShellLangStringW
  17. #define MLLoadResources MLLoadResourcesW
  18. #else
  19. #define MLLoadString MLLoadStringA
  20. #define MLLoadShellLangString MLLoadShellLangStringA
  21. #define MLLoadResources MLLoadResourcesA
  22. #endif
  23. void MLFreeResources(HINSTANCE hinstParent);
  24. HINSTANCE MLGetHinst();
  25. HINSTANCE MLLoadShellLangResources();
  26. void ResWinHelp(HWND hwnd, int ids, int id2, DWORD_PTR dwp);
  27. #ifdef MLUI_MESSAGEBOX
  28. int MLShellMessageBox(HWND hWnd, LPCTSTR pszMsg, LPCTSTR pszTitle, UINT fuStyle, ...);
  29. #endif
  30. //
  31. // The following should be both A and W suffixed
  32. //
  33. int MLLoadStringA(UINT id, LPSTR sz, UINT cchMax);
  34. int MLLoadStringW(UINT id, LPWSTR sz, UINT cchMax);
  35. int MLLoadShellLangStringA(UINT id, LPSTR sz, UINT cchMax);
  36. int MLLoadShellLangStringW(UINT id, LPWSTR sz, UINT cchMax);
  37. void MLLoadResourcesA(HINSTANCE hinstParent, LPSTR pszLocResDll);
  38. void MLLoadResourcesW(HINSTANCE hinstParent, LPWSTR pszLocResDll);
  39. //
  40. // End of: The following should be both A and W suffixed
  41. //
  42. #ifdef MLUI_INIT
  43. // WARNING: do not attempt to access any of these members directly
  44. // these members may not be initialized until appropriate accessors
  45. // are called, for example hinstLocRes won't be intialized until
  46. // you call MLGetHinst()... so just call the accessor.
  47. struct tagMLUI_INFO
  48. {
  49. HINSTANCE hinstLocRes;
  50. HINSTANCE hinstParent;
  51. WCHAR szLocResDll[MAX_PATH];
  52. DWORD dwCrossCodePage;
  53. } g_mluiInfo;
  54. // REARCHITECT: These aren't thread safe... Do they need to be?
  55. //
  56. void MLLoadResourcesA(HINSTANCE hinstParent, LPSTR pszLocResDll)
  57. {
  58. if (g_mluiInfo.hinstLocRes == NULL)
  59. {
  60. #ifdef MLUI_SUPPORT
  61. // plugUI: resource dll == ?
  62. // resource dll must be dynamically determined and loaded.
  63. // but we are NOT allowed to LoadLibrary during process attach.
  64. // therefore we cache the info we need and load later when
  65. // the first resource is requested.
  66. SHAnsiToUnicode(pszLocResDll, g_mluiInfo.szLocResDll, sizeof(g_mluiInfo.szLocResDll)/sizeof(g_mluiInfo.szLocResDll[0]));
  67. g_mluiInfo.hinstParent = hinstParent;
  68. g_mluiInfo.dwCrossCodePage = ML_CROSSCODEPAGE;
  69. #else
  70. // non-plugUI: resource dll == parent dll
  71. g_mluiInfo.hinstLocRes = hinstParent;
  72. #endif
  73. }
  74. }
  75. void MLLoadResourcesW(HINSTANCE hinstParent, LPWSTR pszLocResDll)
  76. {
  77. if (g_mluiInfo.hinstLocRes == NULL)
  78. {
  79. #ifdef MLUI_SUPPORT
  80. // plugUI: resource dll == ?
  81. // resource dll must be dynamically determined and loaded.
  82. // but we are NOT allowed to LoadLibrary during process attach.
  83. // therefore we cache the info we need and load later when
  84. // the first resource is requested.
  85. StrCpyNW(g_mluiInfo.szLocResDll, pszLocResDll, sizeof(g_mluiInfo.szLocResDll)/sizeof(g_mluiInfo.szLocResDll[0]));
  86. g_mluiInfo.hinstParent = hinstParent;
  87. g_mluiInfo.dwCrossCodePage = ML_CROSSCODEPAGE;
  88. #else
  89. // non-plugUI: resource dll == parent dll
  90. g_mluiInfo.hinstLocRes = hinstParent;
  91. #endif
  92. }
  93. }
  94. void
  95. MLFreeResources(HINSTANCE hinstParent)
  96. {
  97. if (g_mluiInfo.hinstLocRes != NULL &&
  98. g_mluiInfo.hinstLocRes != hinstParent)
  99. {
  100. MLClearMLHInstance(g_mluiInfo.hinstLocRes);
  101. g_mluiInfo.hinstLocRes = NULL;
  102. }
  103. }
  104. // this is a private internal helper.
  105. // don't you dare call it from anywhere except at
  106. // the beginning of new ML* functions in this file
  107. __inline void
  108. _MLResAssure()
  109. {
  110. #ifdef MLUI_SUPPORT
  111. if(g_mluiInfo.hinstLocRes == NULL)
  112. {
  113. g_mluiInfo.hinstLocRes = MLLoadLibraryW(g_mluiInfo.szLocResDll,
  114. g_mluiInfo.hinstParent,
  115. g_mluiInfo.dwCrossCodePage);
  116. // we're guaranteed to at least have resources in the install language
  117. ASSERT(g_mluiInfo.hinstLocRes != NULL);
  118. }
  119. #endif
  120. }
  121. int
  122. MLLoadStringA(UINT id, LPSTR sz, UINT cchMax)
  123. {
  124. _MLResAssure();
  125. return LoadStringA(g_mluiInfo.hinstLocRes, id, sz, cchMax);
  126. }
  127. int
  128. MLLoadStringW(UINT id, LPWSTR sz, UINT cchMax)
  129. {
  130. _MLResAssure();
  131. return LoadStringWrapW(g_mluiInfo.hinstLocRes, id, sz, cchMax);
  132. }
  133. int
  134. MLLoadShellLangStringA(UINT id, LPSTR sz, UINT cchMax)
  135. {
  136. HINSTANCE hinstShellLangRes;
  137. int nRet;
  138. hinstShellLangRes = MLLoadShellLangResources();
  139. nRet = LoadStringA(hinstShellLangRes, id, sz, cchMax);
  140. MLFreeLibrary(hinstShellLangRes);
  141. return nRet;
  142. }
  143. int
  144. MLLoadShellLangStringW(UINT id, LPWSTR sz, UINT cchMax)
  145. {
  146. HINSTANCE hinstShellLangRes;
  147. int nRet;
  148. hinstShellLangRes = MLLoadShellLangResources();
  149. nRet = LoadStringWrapW(hinstShellLangRes, id, sz, cchMax);
  150. MLFreeLibrary(hinstShellLangRes);
  151. return nRet;
  152. }
  153. HINSTANCE
  154. MLGetHinst()
  155. {
  156. _MLResAssure();
  157. return g_mluiInfo.hinstLocRes;
  158. }
  159. HINSTANCE
  160. MLLoadShellLangResources()
  161. {
  162. HINSTANCE hinst;
  163. hinst = MLLoadLibraryW(g_mluiInfo.szLocResDll,
  164. g_mluiInfo.hinstParent,
  165. ML_SHELL_LANGUAGE);
  166. // we're guaranteed to at least have resources in the install language
  167. // unless we're 100% toasted
  168. return hinst;
  169. }
  170. BOOL
  171. MLWinHelpWrap(HWND hwndCaller,
  172. LPCTSTR lpszHelp,
  173. UINT uCommand,
  174. DWORD_PTR dwData)
  175. {
  176. BOOL fRet;
  177. #ifdef MLUI_SUPPORT
  178. fRet = MLWinHelp(hwndCaller,
  179. lpszHelp,
  180. uCommand,
  181. dwData);
  182. #else
  183. fRet = WinHelp(hwndCaller,
  184. lpszHelp,
  185. uCommand,
  186. dwData);
  187. #endif
  188. return fRet;
  189. }
  190. LPTSTR LoadSz(UINT idString, LPTSTR lpszBuf, UINT cbBuf)
  191. {
  192. // Clear the buffer and load the string
  193. if ( lpszBuf )
  194. {
  195. *lpszBuf = '\0';
  196. MLLoadString( idString, lpszBuf, cbBuf );
  197. }
  198. return lpszBuf;
  199. }
  200. void ResWinHelp(HWND hwnd, int ids, int id2, DWORD_PTR dwp)
  201. {
  202. TCHAR szSmallBuf[50+1];
  203. MLWinHelpWrap((HWND)hwnd, LoadSz(ids,szSmallBuf,sizeof(szSmallBuf)),
  204. id2, (DWORD_PTR)dwp);
  205. }
  206. #endif // MLUI_INIT
  207. #ifdef __cplusplus
  208. };
  209. #endif
  210. #endif // _INC_MLUISUPP