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.

649 lines
12 KiB

  1. #include <windows.h>
  2. #include <ole2.h>
  3. #include "olethunk.h"
  4. STDAPI_(LPVOID) OleStdMalloc(ULONG ulSize);
  5. STDAPI_(void) OleStdFree(LPVOID pmem);
  6. STDAPI_(void) CopyAndFreeOLESTR(LPOLESTR polestr, LPSTR *ppszOut)
  7. {
  8. // See if there is any work
  9. if (polestr == NULL)
  10. {
  11. if (ppszOut != NULL)
  12. {
  13. // Output string requested so set it to NULL.
  14. *ppszOut = NULL;
  15. }
  16. return;
  17. }
  18. if (ppszOut)
  19. {
  20. // Copy of string converted to ANSI is requested
  21. int len = wcslen(polestr) + 1;
  22. *ppszOut = OleStdMalloc(len);
  23. if (*ppszOut)
  24. {
  25. wcstombs(*ppszOut, polestr, len);
  26. }
  27. }
  28. // Free the original string
  29. OleStdFree(polestr);
  30. }
  31. STDAPI_(void) CopyAndFreeSTR(LPSTR pstr, LPOLESTR *ppolestrOut)
  32. {
  33. // See if there is any work
  34. if (pstr == NULL)
  35. {
  36. if (ppolestrOut != NULL)
  37. {
  38. // Output string requested so set it to NULL.
  39. *ppolestrOut = NULL;
  40. }
  41. return;
  42. }
  43. if (ppolestrOut)
  44. {
  45. // Copy of string converted to ANSI is requested
  46. int len = strlen(pstr) + 1;
  47. *ppolestrOut = OleStdMalloc(len * sizeof(WCHAR));
  48. if (*ppolestrOut)
  49. {
  50. mbstowcs(*ppolestrOut, pstr, len);
  51. }
  52. }
  53. // Free the original string
  54. OleStdFree(pstr);
  55. }
  56. STDAPI_(LPOLESTR) CreateOLESTR(LPCSTR pszIn)
  57. {
  58. // Return NULL if there was no string input
  59. LPOLESTR polestr = NULL;
  60. if (pszIn != NULL)
  61. {
  62. // Calculate size of string to allocate
  63. int len = strlen(pszIn) + 1;
  64. // Allocate the string
  65. polestr = (LPOLESTR) OleStdMalloc(len * sizeof(OLECHAR));
  66. // Convert the string
  67. if (polestr)
  68. {
  69. mbstowcs(polestr, pszIn, len);
  70. }
  71. }
  72. return polestr;
  73. }
  74. STDAPI_(LPSTR) CreateSTR(LPCOLESTR polestrIn)
  75. {
  76. // Return NULL if there was no string input
  77. LPSTR pstr = NULL;
  78. if (polestrIn != NULL)
  79. {
  80. // Calculate size of string to allocate
  81. int len = wcslen(polestrIn) + 1;
  82. // Allocate the string
  83. pstr = (PSTR) OleStdMalloc(len);
  84. // Convert the string
  85. if (pstr)
  86. {
  87. wcstombs(pstr, polestrIn, len);
  88. }
  89. }
  90. return pstr;
  91. }
  92. STDAPI_(void) CLSIDFromStringA(LPSTR pszClass, LPCLSID pclsid)
  93. {
  94. CREATEOLESTR(polestr, pszClass)
  95. CLSIDFromString(polestr, pclsid);
  96. FREEOLESTR(polestr)
  97. }
  98. STDAPI CreateFileMonikerA(LPSTR lpszPathName, LPMONIKER FAR* ppmk)
  99. {
  100. CREATEOLESTR(polestr, lpszPathName)
  101. HRESULT hr = CreateFileMoniker(polestr, ppmk);
  102. FREEOLESTR(polestr)
  103. return hr;
  104. }
  105. STDAPI CreateItemMonikerA(
  106. LPSTR lpszDelim,
  107. LPSTR lpszItem,
  108. LPMONIKER FAR* ppmk)
  109. {
  110. CREATEOLESTR(polestrDelim, lpszDelim)
  111. CREATEOLESTR(polestrItem, lpszItem)
  112. HRESULT hr = CreateItemMoniker(polestrDelim, polestrItem, ppmk);
  113. FREEOLESTR(polestrDelim)
  114. FREEOLESTR(polestrItem)
  115. return hr;
  116. }
  117. STDAPI_(HGLOBAL) OleGetIconOfClassA(
  118. REFCLSID rclsid,
  119. LPSTR lpszLabel,
  120. BOOL fUseTypeAsLabel)
  121. {
  122. CREATEOLESTR(polestr, lpszLabel)
  123. HGLOBAL hglobal = OleGetIconOfClass(rclsid, polestr, fUseTypeAsLabel);
  124. FREEOLESTR(polestr)
  125. return hglobal;
  126. }
  127. STDAPI_(HGLOBAL) OleGetIconOfFileA(LPSTR lpszPath, BOOL fUseFileAsLabel)
  128. {
  129. CREATEOLESTR(polestr, lpszPath)
  130. HGLOBAL hMetaPict = OleGetIconOfFile(polestr, fUseFileAsLabel);
  131. FREEOLESTR(polestr)
  132. return hMetaPict;
  133. }
  134. STDAPI_(HGLOBAL) OleMetafilePictFromIconAndLabelA(
  135. HICON hIcon,
  136. LPSTR lpszLabel,
  137. LPSTR lpszSourceFile,
  138. UINT iIconIndex)
  139. {
  140. CREATEOLESTR(polestrLabel, lpszLabel)
  141. CREATEOLESTR(polestrSourceFile, lpszSourceFile)
  142. HGLOBAL hglobal = OleMetafilePictFromIconAndLabel(hIcon, polestrLabel,
  143. polestrSourceFile, iIconIndex);
  144. FREEOLESTR(polestrLabel)
  145. FREEOLESTR(polestrSourceFile)
  146. return hglobal;
  147. }
  148. STDAPI GetClassFileA(LPCSTR szFilename, CLSID FAR* pclsid)
  149. {
  150. CREATEOLESTR(polestr, szFilename)
  151. HRESULT hr = GetClassFile(polestr, pclsid);
  152. FREEOLESTR(polestr)
  153. return hr;
  154. }
  155. STDAPI CLSIDFromProgIDA(LPCSTR lpszProgID, LPCLSID lpclsid)
  156. {
  157. CREATEOLESTR(polestr, lpszProgID)
  158. HRESULT hr = CLSIDFromProgID(polestr, lpclsid);
  159. FREEOLESTR(polestr)
  160. return hr;
  161. }
  162. STDAPI MkParseDisplayNameA(
  163. LPBC pbc,
  164. LPSTR szUserName,
  165. ULONG FAR * pchEaten,
  166. LPMONIKER FAR * ppmk)
  167. {
  168. CREATEOLESTR(polestr, szUserName)
  169. HRESULT hr = MkParseDisplayName(pbc, polestr, pchEaten, ppmk);
  170. FREEOLESTR(polestr)
  171. return hr;
  172. }
  173. STDAPI OleCreateLinkToFileA(
  174. LPCSTR lpszFileName,
  175. REFIID riid,
  176. DWORD renderopt,
  177. LPFORMATETC lpFormatEtc,
  178. LPOLECLIENTSITE pClientSite,
  179. LPSTORAGE pStg,
  180. LPVOID FAR* ppvObj)
  181. {
  182. CREATEOLESTR(polestr, lpszFileName)
  183. HRESULT hr = OleCreateLinkToFile(polestr, riid, renderopt, lpFormatEtc,
  184. pClientSite, pStg, ppvObj);
  185. FREEOLESTR(polestr)
  186. return hr;
  187. }
  188. STDAPI OleCreateFromFileA(
  189. REFCLSID rclsid,
  190. LPCSTR lpszFileName,
  191. REFIID riid,
  192. DWORD renderopt,
  193. LPFORMATETC lpFormatEtc,
  194. LPOLECLIENTSITE pClientSite,
  195. LPSTORAGE pStg,
  196. LPVOID FAR* ppvObj)
  197. {
  198. CREATEOLESTR(polestr, lpszFileName)
  199. HRESULT hr = OleCreateFromFile(rclsid, polestr, riid, renderopt,
  200. lpFormatEtc, pClientSite, pStg, ppvObj);
  201. FREEOLESTR(polestr)
  202. return hr;
  203. }
  204. STDAPI OleRegGetUserTypeA(
  205. REFCLSID clsid,
  206. DWORD dwFormOfType,
  207. LPSTR FAR* ppszUserType)
  208. {
  209. LPOLESTR polestr;
  210. HRESULT hr = OleRegGetUserType(clsid, dwFormOfType, &polestr);
  211. CopyAndFreeOLESTR(polestr, ppszUserType);
  212. return hr;
  213. }
  214. STDAPI ProgIDFromCLSIDA(REFCLSID clsid, LPSTR FAR* lplpszProgID)
  215. {
  216. LPOLESTR polestr;
  217. HRESULT hr = ProgIDFromCLSID(clsid, &polestr);
  218. CopyAndFreeOLESTR(polestr, lplpszProgID);
  219. return hr;
  220. }
  221. STDAPI ReadFmtUserTypeStgA(
  222. LPSTORAGE pstg,
  223. CLIPFORMAT FAR* pcf,
  224. LPSTR FAR* lplpszUserType)
  225. {
  226. LPOLESTR polestr;
  227. HRESULT hr = ReadFmtUserTypeStg(pstg, pcf, &polestr);
  228. CopyAndFreeOLESTR(polestr, lplpszUserType);
  229. return hr;
  230. }
  231. STDAPI StgCreateDocfileA(
  232. LPCSTR lpszName,
  233. DWORD grfMode,
  234. DWORD reserved,
  235. IStorage FAR * FAR *ppstgOpen)
  236. {
  237. HRESULT hr;
  238. LPOLESTR polestr = NULL;
  239. if (lpszName != NULL)
  240. {
  241. polestr = CreateOLESTR(lpszName);
  242. }
  243. hr = StgCreateDocfile(polestr, grfMode, reserved, ppstgOpen);
  244. FREEOLESTR(polestr)
  245. return hr;
  246. }
  247. STDAPI StgOpenStorageA(
  248. LPCSTR lpszName,
  249. IStorage FAR *pstgPriority,
  250. DWORD grfMode,
  251. SNB snbExclude,
  252. DWORD reserved,
  253. IStorage FAR * FAR *ppstgOpen)
  254. {
  255. CREATEOLESTR(polestr, lpszName)
  256. HRESULT hr = StgOpenStorage(polestr, pstgPriority, grfMode, snbExclude,
  257. reserved, ppstgOpen);
  258. FREEOLESTR(polestr)
  259. return hr;
  260. }
  261. STDAPI StgSetTimesA(
  262. LPSTR lpszName,
  263. FILETIME const FAR* pctime,
  264. FILETIME const FAR* patime,
  265. FILETIME const FAR* pmtime)
  266. {
  267. CREATEOLESTR(polestr, lpszName)
  268. HRESULT hr = StgSetTimes(polestr, pctime, patime, pmtime);
  269. FREEOLESTR(polestr)
  270. return hr;
  271. }
  272. STDAPI_(void) StringFromCLSIDA(REFCLSID rclsid, LPSTR *lplpszCLSID)
  273. {
  274. LPOLESTR polestr;
  275. StringFromCLSID(rclsid, &polestr);
  276. CopyAndFreeOLESTR(polestr, lplpszCLSID);
  277. }
  278. STDAPI WriteFmtUserTypeStgA(
  279. LPSTORAGE lpStg,
  280. CLIPFORMAT cf,
  281. LPSTR lpszUserType)
  282. {
  283. CREATEOLESTR(polestr, lpszUserType)
  284. HRESULT hr = WriteFmtUserTypeStg(lpStg, cf, polestr);
  285. FREEOLESTR(polestr)
  286. return hr;
  287. }
  288. STDAPI CallIMonikerGetDisplayNameA(
  289. LPMONIKER lpmk,
  290. IBindCtx *pbc,
  291. IMoniker *pmkToLeft,
  292. LPSTR *ppszDisplayName)
  293. {
  294. LPOLESTR polestr;
  295. HRESULT hr = lpmk->lpVtbl->GetDisplayName(lpmk, pbc, NULL,
  296. &polestr);
  297. CopyAndFreeOLESTR(polestr, ppszDisplayName);
  298. return hr;
  299. }
  300. STDAPI CallIOleInPlaceUIWindowSetActiveObjectA(
  301. IOleInPlaceUIWindow FAR *lpthis,
  302. IOleInPlaceActiveObject *pActiveObject,
  303. LPCSTR pszObjName)
  304. {
  305. CREATEOLESTR(polestr, pszObjName)
  306. HRESULT hr = lpthis->lpVtbl->SetActiveObject(lpthis, pActiveObject,
  307. polestr);
  308. FREEOLESTR(polestr)
  309. return hr;
  310. }
  311. STDAPI CallIOleInPlaceFrameSetStatusTextA(
  312. IOleInPlaceFrame *poleinplc,
  313. LPCSTR pszStatusText)
  314. {
  315. CREATEOLESTR(polestr, pszStatusText)
  316. HRESULT hr = poleinplc->lpVtbl->SetStatusText(poleinplc, polestr);
  317. FREEOLESTR(polestr)
  318. return hr;
  319. }
  320. STDAPI CallIOleLinkGetSourceDisplayNameA(
  321. IOleLink FAR *polelink,
  322. LPSTR *ppszDisplayName)
  323. {
  324. LPOLESTR polestr;
  325. HRESULT hr = polelink->lpVtbl->GetSourceDisplayName(polelink, &polestr);
  326. CopyAndFreeOLESTR(polestr, ppszDisplayName);
  327. return hr;
  328. }
  329. STDAPI CallIOleLinkSetSourceDisplayNameA(
  330. IOleLink FAR *polelink,
  331. LPCSTR pszStatusText)
  332. {
  333. CREATEOLESTR(polestr, pszStatusText)
  334. HRESULT hr = polelink->lpVtbl->SetSourceDisplayName(polelink, polestr);
  335. FREEOLESTR(polestr)
  336. return hr;
  337. }
  338. STDAPI CallIOleObjectGetUserTypeA(
  339. LPOLEOBJECT lpOleObject,
  340. DWORD dwFormOfType,
  341. LPSTR *ppszUserType)
  342. {
  343. LPOLESTR polestr;
  344. HRESULT hr = lpOleObject->lpVtbl->GetUserType(lpOleObject,
  345. dwFormOfType, &polestr);
  346. CopyAndFreeOLESTR(polestr, ppszUserType);
  347. return hr;
  348. }
  349. STDAPI CallIOleObjectSetHostNamesA(
  350. LPOLEOBJECT lpOleObject,
  351. LPCSTR szContainerApp,
  352. LPCSTR szContainerObj)
  353. {
  354. CREATEOLESTR(polestrApp, szContainerApp)
  355. CREATEOLESTR(polestrObj, szContainerObj)
  356. HRESULT hr = lpOleObject->lpVtbl->SetHostNames(lpOleObject, polestrApp,
  357. polestrObj);
  358. FREEOLESTR(polestrApp)
  359. FREEOLESTR(polestrObj)
  360. return hr;
  361. }
  362. STDAPI CallIStorageDestroyElementA(
  363. LPSTORAGE lpStg,
  364. LPSTR pszName)
  365. {
  366. CREATEOLESTR(polestr, pszName)
  367. HRESULT hr = lpStg->lpVtbl->DestroyElement(lpStg, polestr);
  368. FREEOLESTR(polestr)
  369. return hr;
  370. }
  371. STDAPI CallIStorageCreateStorageA(
  372. LPSTORAGE lpStg,
  373. const char *pszName,
  374. DWORD grfMode,
  375. DWORD dwStgFmt,
  376. DWORD reserved2,
  377. IStorage **ppstg)
  378. {
  379. CREATEOLESTR(polestr, pszName)
  380. HRESULT hr = lpStg->lpVtbl->CreateStorage(lpStg, polestr, grfMode,
  381. dwStgFmt, reserved2, ppstg);
  382. FREEOLESTR(polestr)
  383. return hr;
  384. }
  385. STDAPI CallIStorageOpenStorageA(
  386. LPSTORAGE lpStg,
  387. const char *pszName,
  388. IStorage *pstgPriority,
  389. DWORD grfMode,
  390. SNB snbExclude,
  391. DWORD reserved,
  392. IStorage **ppstg)
  393. {
  394. CREATEOLESTR(polestr, pszName)
  395. HRESULT hr = lpStg->lpVtbl->OpenStorage(lpStg, polestr, pstgPriority,
  396. grfMode, snbExclude, reserved, ppstg);
  397. FREEOLESTR(polestr)
  398. return hr;
  399. }
  400. STDAPI CallIStorageCreateStreamA(
  401. LPSTORAGE lpStg,
  402. LPSTR pszName,
  403. DWORD grfMode,
  404. DWORD reserved1,
  405. DWORD reserved2,
  406. IStream **ppstm)
  407. {
  408. CREATEOLESTR(polestr, pszName)
  409. HRESULT hr = lpStg->lpVtbl->CreateStream(lpStg, polestr,
  410. grfMode, reserved1, reserved2, ppstm);
  411. FREEOLESTR(polestr)
  412. return hr;
  413. }
  414. STDAPI CallIStorageOpenStreamA(
  415. LPSTORAGE lpStg,
  416. LPSTR pszName,
  417. void *reserved1,
  418. DWORD grfMode,
  419. DWORD reserved2,
  420. IStream **ppstm)
  421. {
  422. CREATEOLESTR(polestr, pszName)
  423. HRESULT hr = lpStg->lpVtbl->OpenStream(lpStg, polestr, reserved1,
  424. grfMode, reserved2, ppstm);
  425. FREEOLESTR(polestr)
  426. return hr;
  427. }