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.

457 lines
11 KiB

  1. /*****************************************************************************
  2. *
  3. * dimapshp.c
  4. *
  5. * Copyright (c) 1997 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * Abstract:
  8. *
  9. * The IDirectInputMapperW shepherd.
  10. *
  11. * The shepherd does the annoying work of babysitting the
  12. * IDirectInputMapperW.
  13. *
  14. * It makes sure nobody parties on bad handles.
  15. *
  16. * It handles cross-process (or even intra-process) effect
  17. * management.
  18. *
  19. * Contents:
  20. *
  21. * CMapShep_New
  22. *
  23. *****************************************************************************/
  24. #include "dinputpr.h"
  25. #ifdef UNICODE
  26. #undef _UNICODE
  27. #define _UNICODE
  28. #endif // !UNICODE
  29. /*****************************************************************************
  30. *
  31. * The sqiffle for this file.
  32. *
  33. *****************************************************************************/
  34. #define sqfl sqflEShep/*Should we use own area?*/
  35. #pragma BEGIN_CONST_DATA
  36. /*****************************************************************************
  37. *
  38. * Declare the interfaces we will be providing.
  39. *
  40. *****************************************************************************/
  41. Primary_Interface(CMapShep, IDirectInputMapShepherd);
  42. /*****************************************************************************
  43. *
  44. * @doc INTERNAL
  45. *
  46. * @struct CMapShep |
  47. *
  48. * The <i IDirectInputMapShepherd> object, which
  49. * babysits an <i IDirectInputMapperW>.
  50. *
  51. * @field IDirectInputMapShepherd | dms |
  52. *
  53. * DirectInputMapShepherd object (containing vtbl).
  54. *
  55. * @field IDirectInputMapperW * | pdimap |
  56. *
  57. * Delegated mapper interface.
  58. *
  59. * @field HINSTANCE | hinstdimapdll |
  60. *
  61. * The instance handle of the DLL that contains the mapper.
  62. *
  63. *****************************************************************************/
  64. typedef struct CMapShep {
  65. /* Supported interfaces */
  66. IDirectInputMapShepherd dms;
  67. IDirectInputMapperW* pdimap;
  68. HINSTANCE hinstdimapdll;
  69. } CMapShep, MS, *PMS;
  70. typedef IDirectInputMapShepherd DMS, *PDMS;
  71. #define ThisClass CMapShep
  72. #define ThisInterface IDirectInputMapShepherd
  73. /*****************************************************************************
  74. *
  75. * @doc EXTERNAL
  76. *
  77. * @method HRESULT | IDirectInputMapShepherd | QueryInterface |
  78. *
  79. * Gives a client access to other interfaces on an object.
  80. *
  81. * @cwrap LPDIRECTINPUT | lpDirectInput
  82. *
  83. * @parm IN REFIID | riid |
  84. *
  85. * The requested interface's IID.
  86. *
  87. * @parm OUT LPVOID * | ppvObj |
  88. *
  89. * Receives a pointer to the obtained interface.
  90. *
  91. * @returns
  92. *
  93. * Returns a COM error code.
  94. *
  95. * @xref OLE documentation for <mf IUnknown::QueryInterface>.
  96. *
  97. *//**************************************************************************
  98. *
  99. * @doc EXTERNAL
  100. *
  101. * @method HRESULT | IDirectInputMapShepherd | AddRef |
  102. *
  103. * Increments the reference count for the interface.
  104. *
  105. * @cwrap LPDIRECTINPUT | lpDirectInput
  106. *
  107. * @returns
  108. *
  109. * Returns the object reference count.
  110. *
  111. * @xref OLE documentation for <mf IUnknown::AddRef>.
  112. *
  113. *****************************************************************************
  114. *
  115. * @doc EXTERNAL
  116. *
  117. * @method HRESULT | IDirectInputMapShepherd | Release |
  118. *
  119. * Decrements the reference count for the interface.
  120. * If the reference count on the object falls to zero,
  121. * the object is freed from memory.
  122. *
  123. * @cwrap LPDIRECTINPUT | lpDirectInput
  124. *
  125. * @returns
  126. *
  127. * Returns the object reference count.
  128. *
  129. * @xref OLE documentation for <mf IUnknown::Release>.
  130. *
  131. *//**************************************************************************
  132. *
  133. * @doc INTERNAL
  134. *
  135. * @method HRESULT | IDirectInputMapShepherd | QIHelper |
  136. *
  137. * We don't have any dynamic interfaces and simply forward
  138. * to <f Common_QIHelper>.
  139. *
  140. * @parm IN REFIID | riid |
  141. *
  142. * The requested interface's IID.
  143. *
  144. * @parm OUT LPVOID * | ppvObj |
  145. *
  146. * Receives a pointer to the obtained interface.
  147. *
  148. *//**************************************************************************
  149. *
  150. * @doc INTERNAL
  151. *
  152. * @method HRESULT | IDirectInputMapShepherd | AppFinalize |
  153. *
  154. * We don't have any weak pointers, so we can just
  155. * forward to <f Common_Finalize>.
  156. *
  157. * @parm PV | pvObj |
  158. *
  159. * Object being released from the application's perspective.
  160. *
  161. *****************************************************************************/
  162. #ifdef DEBUG
  163. Default_QueryInterface(CMapShep)
  164. Default_AddRef(CMapShep)
  165. Default_Release(CMapShep)
  166. #else
  167. #define CMapShep_QueryInterface Common_QueryInterface
  168. #define CMapShep_AddRef Common_AddRef
  169. #define CMapShep_Release Common_Release
  170. #endif
  171. #define CMapShep_QIHelper Common_QIHelper
  172. #define CMapShep_AppFinalize Common_AppFinalize
  173. /*****************************************************************************
  174. *
  175. * @doc INTERNAL
  176. *
  177. * @func void | CMapShep_Finalize |
  178. *
  179. * Clean up our instance data.
  180. *
  181. * @parm PV | pvObj |
  182. *
  183. * Object being released. Note that it may not have been
  184. * completely initialized, so everything should be done
  185. * carefully.
  186. *
  187. *****************************************************************************/
  188. void INTERNAL
  189. CMapShep_Finalize(PV pvObj)
  190. {
  191. PMS this = pvObj;
  192. Invoke_Release(&this->pdimap);
  193. if( this->hinstdimapdll)
  194. {
  195. FreeLibrary(this->hinstdimapdll);
  196. this->hinstdimapdll = NULL;
  197. }
  198. }
  199. /*****************************************************************************
  200. * ForceUnload
  201. *****************************************************************************/
  202. void INTERNAL
  203. CMapShep_ForceUnload(PV pvObj)/**why are this two functions same??????**/
  204. {
  205. PMS this = pvObj;
  206. Invoke_Release(&this->pdimap);
  207. if( this->hinstdimapdll)
  208. {
  209. FreeLibrary(this->hinstdimapdll);
  210. this->hinstdimapdll = NULL;
  211. }
  212. }
  213. /*****************************************************************************
  214. * InitDll
  215. *****************************************************************************/
  216. HRESULT INTERNAL
  217. CMapShep_InitDll(PMS this,REFGUID lpDeviceGUID,LPCWSTR lpcwstrFileName)
  218. {
  219. //do _CreateInstance()
  220. HRESULT hres = S_OK;
  221. if (this->hinstdimapdll == NULL)
  222. {
  223. hres = _CreateInstance(&IID_IDirectInputMapClsFact/*should be CLSID_CDIMap*/,
  224. TEXT("dimap.dll"), NULL, &IID_IDirectInputMapIW,
  225. (LPVOID*) & this->pdimap, &this->hinstdimapdll);
  226. if (SUCCEEDED(hres) && this->pdimap != NULL)
  227. {
  228. hres = this->pdimap->lpVtbl->Initialize(this->pdimap,
  229. lpDeviceGUID, lpcwstrFileName, 0);
  230. if(!SUCCEEDED(hres))
  231. CMapShep_Finalize(this);
  232. }
  233. }
  234. return hres;
  235. }
  236. /*****************************************************************************
  237. * GetActionMap
  238. *****************************************************************************/
  239. STDMETHODIMP
  240. CMapShep_GetActionMapW
  241. (
  242. PDMS pdms,
  243. REFGUID lpDeviceGUID,
  244. LPCWSTR lpcwstrFileName,
  245. LPDIACTIONFORMATW lpDIActionFormat,
  246. LPCWSTR lpcwstrUserName,
  247. LPFILETIME lpFileTime,
  248. DWORD dwFlags
  249. )
  250. {
  251. PMS this;
  252. HRESULT hres = S_OK;
  253. EnterProcI(IDirectInputMapShepherd::GetActionMapW, (_ "p", pdms));
  254. this = _thisPvNm(pdms, dms);
  255. if (!this->hinstdimapdll)
  256. {
  257. hres = CMapShep_InitDll(this, lpDeviceGUID, lpcwstrFileName);
  258. }
  259. //call the fn
  260. if (SUCCEEDED(hres) && this->pdimap != NULL)
  261. {
  262. hres = this->pdimap->lpVtbl->GetActionMap(this->pdimap,
  263. lpDIActionFormat, lpcwstrUserName, lpFileTime, dwFlags );
  264. }
  265. ExitOleProcR();
  266. return hres;
  267. }
  268. /*****************************************************************************
  269. * SaveActionMap
  270. *****************************************************************************/
  271. STDMETHODIMP
  272. CMapShep_SaveActionMapW
  273. (
  274. PDMS pdms,
  275. REFGUID lpDeviceGUID,
  276. LPCWSTR lpcwstrFileName,
  277. LPDIACTIONFORMATW lpDIActionFormat,
  278. LPCWSTR lpcwstrUserName,
  279. DWORD dwFlags)
  280. {
  281. PMS this;
  282. HRESULT hres = S_OK;
  283. EnterProcI(IDirectInputMapShepherd::SaveActionMapW, (_ "p", pdms));
  284. this = _thisPvNm(pdms, dms);
  285. if (!this->hinstdimapdll)
  286. {
  287. hres = CMapShep_InitDll(this, lpDeviceGUID, lpcwstrFileName);
  288. }
  289. //call the fn
  290. if (SUCCEEDED(hres) && this->pdimap != NULL)
  291. {
  292. hres = this->pdimap->lpVtbl->SaveActionMap(this->pdimap,
  293. lpDIActionFormat, lpcwstrUserName, dwFlags );
  294. }
  295. // CMapShep_Finalize(this);
  296. ExitOleProcR();
  297. return hres;
  298. }
  299. /*****************************************************************************
  300. * GetImageInfo
  301. *****************************************************************************/
  302. STDMETHODIMP
  303. CMapShep_GetImageInfoW
  304. (
  305. PDMS pdms,
  306. REFGUID lpDeviceGUID,
  307. LPCWSTR lpcwstrFileName,
  308. LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader
  309. )
  310. {
  311. PMS this;
  312. HRESULT hres = S_OK;
  313. EnterProcI(IDirectInputMapShepherd::GetImageInfoW, (_ "p", pdms));
  314. this = _thisPvNm(pdms, dms);
  315. if (!this->hinstdimapdll)
  316. {
  317. hres = CMapShep_InitDll(this, lpDeviceGUID, lpcwstrFileName);
  318. }
  319. //call the fn
  320. if (SUCCEEDED(hres) && this->pdimap != NULL)
  321. {
  322. hres = this->pdimap->lpVtbl->GetImageInfo(this->pdimap,
  323. lpdiDevImageInfoHeader );
  324. }
  325. ExitOleProcR();
  326. return hres;
  327. }
  328. /*****************************************************************************
  329. *
  330. * @doc INTERNAL
  331. *
  332. * @method HRESULT | IDirectInputMapShepherd | New |
  333. *
  334. * Create a new instance of an IDirectInputMapShepherd object.
  335. *
  336. * @parm IN PUNK | punkOuter |
  337. *
  338. * Controlling unknown for aggregation.
  339. *
  340. * @parm IN RIID | riid |
  341. *
  342. * Desired interface to new object.
  343. *
  344. * @parm OUT PPV | ppvObj |
  345. *
  346. * Output pointer for new object.
  347. *
  348. * @returns
  349. *
  350. * Standard OLE <t HRESULT>.
  351. *
  352. *****************************************************************************/
  353. STDMETHODIMP
  354. CMapShep_New(PUNK punkOuter, RIID riid, PPV ppvObj)
  355. {
  356. HRESULT hres;
  357. EnterProcR(IDirectInputMapShepherd::<constructor>, (_ "G", riid));
  358. hres = Common_NewRiid(CMapShep, punkOuter, riid, ppvObj);
  359. if (SUCCEEDED(hres)) {
  360. /* Must use _thisPv in case of aggregation */
  361. PMS this = _thisPv(*ppvObj);
  362. this->hinstdimapdll = NULL;
  363. /* In case of mapper we do this inside each method...
  364. if (SUCCEEDED(hres = CMap_InitDll(this))) {
  365. } else {
  366. Invoke_Release(ppvObj);
  367. }*/
  368. }
  369. ExitOleProcPpvR(ppvObj);
  370. return hres;
  371. }
  372. /*****************************************************************************
  373. *
  374. * The long-awaited vtbls and templates
  375. *
  376. *****************************************************************************/
  377. #pragma BEGIN_CONST_DATA
  378. //#define CEShep_Signature 0x50454853 /* "SHEP" */
  379. Interface_Template_Begin(CMapShep)
  380. Primary_Interface_Template(CMapShep, IDirectInputMapShepherd)
  381. Interface_Template_End(CMapShep)
  382. Primary_Interface_Begin(CMapShep, IDirectInputMapShepherd)
  383. CMapShep_GetActionMapW,
  384. CMapShep_SaveActionMapW,
  385. CMapShep_GetImageInfoW,
  386. Primary_Interface_End(CMapShep, IDirectInputMapShepherd)