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.

1866 lines
51 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: transmit.cxx
  7. //
  8. // Contents: Support for Windows/OLE data types for oleprx32.dll.
  9. // Used to be transmit_as routines, now user_marshal routines.
  10. //
  11. // Functions:
  12. // HBRUSH_UserSize
  13. // HBRUSH_UserMarshal
  14. // HBRUSH_UserUnmarshal
  15. // HBRUSH_UserFree
  16. // HACCEL_UserSize
  17. // HACCEL_UserMarshal
  18. // HACCEL_UserUnmarshal
  19. // HACCEL_UserFree
  20. // HWND_UserSize
  21. // HWND_UserMarshal
  22. // HWND_UserUnmarshal
  23. // HWND_UserFree
  24. // HMENU_UserSize
  25. // HMENU_UserMarshal
  26. // HMENU_UserUnmarshal
  27. // HMENU_UserFree
  28. // HICON_User*
  29. // HDC_UserSize
  30. // HDC_UserMarshal
  31. // HDC_UserUnmarshal
  32. // HDC_UserFree
  33. //
  34. // History: 24-Aug-93 ShannonC Created
  35. // 24-Nov-93 ShannonC Added HGLOBAL
  36. // 14-May-94 DavePl Added HENHMETAFILE
  37. // 18-May-94 ShannonC Added HACCEL, UINT, WPARAM
  38. // 19-May-94 DavePl Added HENHMETAFILE to STGMEDIUM code
  39. // May-95 Ryszardk Wrote all the _User* routines
  40. // Feb-96 Ryszardk Added CLIPFORMAT support
  41. // 25-Jun-99 a-olegi Added HDC code
  42. // 14-Dec-00 JohnDoty Because the size of the code nearly
  43. // doubled for NDR64, factored out the
  44. // involved routines to seperate files.
  45. // see:
  46. // clipformat.cxx
  47. // bitmap.cxx
  48. // hpalette.cxx
  49. // metafile.cxx
  50. // snb.cxx
  51. // hglobal.cxx
  52. // stgmedium.cxx
  53. //
  54. //--------------------------------------------------------------------------
  55. #include "stdrpc.hxx"
  56. #pragma hdrstop
  57. #include <oleauto.h>
  58. #include <objbase.h>
  59. #include "transmit.hxx"
  60. #include <rpcwdt.h>
  61. #include <storext.h>
  62. #include "widewrap.h"
  63. #include <valid.h>
  64. #include <obase.h>
  65. #include <stream.hxx>
  66. WINOLEAPI_(void) ReleaseStgMedium(LPSTGMEDIUM pStgMed);
  67. #pragma code_seg(".orpc")
  68. EXTERN_C const CLSID CLSID_MyPSFactoryBuffer = {0x6f11fe5c,0x2fc5,0x101b,{0x9e,0x45,0x00,0x00,0x0b,0x65,0xc7,0xef}};
  69. // Used to detect if the channel is a CRpcChannelBuffer object
  70. extern const IID IID_CPPRpcChannelBuffer;
  71. class CRpcChannelBuffer;
  72. extern HRESULT GetIIDFromObjRef(OBJREF &objref, IID **piid);
  73. // These methods are needed as the object is used for interface marshaling.
  74. /***************************************************************************/
  75. STDMETHODIMP_(ULONG) CStreamOnMessage::AddRef( THIS )
  76. {
  77. return ref_count += 1;
  78. }
  79. /***************************************************************************/
  80. STDMETHODIMP CStreamOnMessage::Clone(THIS_ IStream * *ppstm)
  81. {
  82. return ResultFromScode(E_NOTIMPL);
  83. }
  84. /***************************************************************************/
  85. STDMETHODIMP CStreamOnMessage::Commit(THIS_ DWORD grfCommitFlags)
  86. {
  87. return ResultFromScode(E_NOTIMPL);
  88. }
  89. /***************************************************************************/
  90. STDMETHODIMP CStreamOnMessage::CopyTo(THIS_ IStream *pstm,
  91. ULARGE_INTEGER cb,
  92. ULARGE_INTEGER *pcbRead,
  93. ULARGE_INTEGER *pcbWritten)
  94. {
  95. return ResultFromScode(E_NOTIMPL);
  96. }
  97. /***************************************************************************/
  98. CStreamOnMessage::CStreamOnMessage(unsigned char **ppMessageBuffer)
  99. : ref_count(1), ppBuffer(ppMessageBuffer), cbMaxStreamLength(0xFFFFFFFF)
  100. {
  101. pStartOfStream = *ppMessageBuffer;
  102. }
  103. /***************************************************************************/
  104. STDMETHODIMP CStreamOnMessage::LockRegion(THIS_ ULARGE_INTEGER libOffset,
  105. ULARGE_INTEGER cb,
  106. DWORD dwLockType)
  107. {
  108. return ResultFromScode(E_NOTIMPL);
  109. }
  110. /***************************************************************************/
  111. STDMETHODIMP CStreamOnMessage::QueryInterface( REFIID riid, LPVOID FAR* ppvObj)
  112. {
  113. if (IsEqualIID(riid, IID_IUnknown))
  114. {
  115. *ppvObj = (IUnknown *) this;
  116. ref_count += 1;
  117. return ResultFromScode(S_OK);
  118. }
  119. else if (IsEqualIID(riid, IID_IStream))
  120. {
  121. *ppvObj = (IStream *) this;
  122. ref_count += 1;
  123. return ResultFromScode(S_OK);
  124. }
  125. else
  126. return ResultFromScode(E_NOINTERFACE);
  127. }
  128. /***************************************************************************/
  129. STDMETHODIMP CStreamOnMessage::Read(THIS_ VOID HUGEP *pv,
  130. ULONG cb, ULONG *pcbRead)
  131. {
  132. memcpy( pv, *ppBuffer, cb );
  133. *ppBuffer += cb;
  134. if (pcbRead != NULL)
  135. *pcbRead = cb;
  136. return ResultFromScode(S_OK);
  137. }
  138. /***************************************************************************/
  139. STDMETHODIMP_(ULONG) CStreamOnMessage::Release( THIS )
  140. {
  141. ref_count -= 1;
  142. if (ref_count == 0)
  143. {
  144. delete this;
  145. return 0;
  146. }
  147. else
  148. return ref_count;
  149. }
  150. /***************************************************************************/
  151. STDMETHODIMP CStreamOnMessage::Revert(THIS)
  152. {
  153. return ResultFromScode(E_NOTIMPL);
  154. }
  155. /***************************************************************************/
  156. STDMETHODIMP CStreamOnMessage::Seek(THIS_ LARGE_INTEGER dlibMove,
  157. DWORD dwOrigin,
  158. ULARGE_INTEGER *plibNewPosition)
  159. {
  160. ULONG pos;
  161. // Verify that the offset isn't out of range.
  162. if (dlibMove.HighPart != 0)
  163. return ResultFromScode( E_FAIL );
  164. // Determine the new seek pointer.
  165. switch (dwOrigin)
  166. {
  167. case STREAM_SEEK_SET:
  168. pos = dlibMove.LowPart;
  169. break;
  170. case STREAM_SEEK_CUR:
  171. /* Must use signed math here. */
  172. pos = (ULONG) (*ppBuffer - pStartOfStream);
  173. if ((long) dlibMove.LowPart < 0 &&
  174. pos < (unsigned long) - (long) dlibMove.LowPart)
  175. return ResultFromScode( E_FAIL );
  176. pos += (long) dlibMove.LowPart;
  177. break;
  178. case STREAM_SEEK_END:
  179. return ResultFromScode(E_NOTIMPL);
  180. break;
  181. default:
  182. return ResultFromScode( E_FAIL );
  183. }
  184. // Set the seek pointer.
  185. *ppBuffer = pStartOfStream + pos;
  186. if (plibNewPosition != NULL)
  187. {
  188. plibNewPosition->LowPart = pos;
  189. plibNewPosition->HighPart = 0;
  190. }
  191. return ResultFromScode(S_OK);
  192. }
  193. /***************************************************************************/
  194. STDMETHODIMP CStreamOnMessage::SetSize(THIS_ ULARGE_INTEGER libNewSize)
  195. {
  196. return ResultFromScode(E_NOTIMPL);
  197. }
  198. /***************************************************************************/
  199. STDMETHODIMP CStreamOnMessage::Stat(THIS_ STATSTG *pstatstg, DWORD grfStatFlag)
  200. {
  201. return ResultFromScode(E_NOTIMPL);
  202. }
  203. /***************************************************************************/
  204. STDMETHODIMP CStreamOnMessage::UnlockRegion(THIS_ ULARGE_INTEGER libOffset,
  205. ULARGE_INTEGER cb,
  206. DWORD dwLockType)
  207. {
  208. return ResultFromScode(E_NOTIMPL);
  209. }
  210. /***************************************************************************/
  211. STDMETHODIMP CStreamOnMessage::Write(THIS_ VOID const HUGEP *pv,
  212. ULONG cb,
  213. ULONG *pcbWritten)
  214. {
  215. // Write the data.
  216. memcpy( *ppBuffer, pv, cb );
  217. if (pcbWritten != NULL)
  218. *pcbWritten = cb;
  219. *ppBuffer += cb;
  220. return ResultFromScode(S_OK);
  221. }
  222. // #########################################################################
  223. //
  224. // WdtpRemotableHandle helper
  225. //
  226. // #########################################################################
  227. //+-------------------------------------------------------------------------
  228. //
  229. // Function: WdtpRemotableHandle_UserSize
  230. //
  231. // Synopsis: Sizes a void star handle as a union with a long.
  232. // Handle size may be 8 bytes but on wire it is still a long.
  233. //
  234. // history: Dec-95 Ryszardk Created.
  235. // Dec-98 Ryszardk Ported to 64b.
  236. //
  237. //--------------------------------------------------------------------------
  238. unsigned long __RPC_USER
  239. WdtpRemotableHandle_UserSize (
  240. unsigned long * pFlags,
  241. unsigned long Offset,
  242. LONG_PTR * pHandle )
  243. {
  244. if ( !pHandle )
  245. return Offset;
  246. if ( *pHandle && DIFFERENT_MACHINE_CALL(*pFlags) )
  247. RAISE_RPC_EXCEPTION( RPC_S_INVALID_TAG );
  248. LENGTH_ALIGN( Offset, 3 );
  249. // 4 bytes for discriminator, 4 bytes for the long.
  250. return( Offset + 8 ) ;
  251. }
  252. //+-------------------------------------------------------------------------
  253. //
  254. // Function: WdtpRemotableHandle_UserMarshall
  255. //
  256. // Synopsis: Marshalls a handle as a union with a long.
  257. // We represent a GDI or USER handle, which may be 4 or 8 bytes,
  258. // as a long on wire.
  259. //
  260. // history: Dec-95 Ryszardk Created.
  261. // Dec-98 Ryszardk Ported to 64b.
  262. //
  263. //--------------------------------------------------------------------------
  264. unsigned char __RPC_FAR * __RPC_USER
  265. WdtpRemotableHandle_UserMarshal (
  266. unsigned long * pFlags,
  267. unsigned char * pBuffer,
  268. LONG_PTR * pHandle )
  269. {
  270. if ( !pHandle )
  271. return pBuffer;
  272. if ( *pHandle && DIFFERENT_MACHINE_CALL(*pFlags) )
  273. RpcRaiseException( RPC_S_INVALID_TAG );
  274. ALIGN( pBuffer, 3 );
  275. *( PULONG_LV_CAST pBuffer)++ = WDT_HANDLE_MARKER;
  276. *( PLONG_LV_CAST pBuffer)++ = (long)*pHandle;
  277. return( pBuffer );
  278. }
  279. //+-------------------------------------------------------------------------
  280. //
  281. // Function: WdtpRemotableHandle_UserUnmarshall
  282. //
  283. // Synopsis: Unmarshalls a remotable void star as union with ulong.
  284. // Handle is represented as a long on wire.
  285. // On 64b platforms, we sign extended it to 8 bytes to get
  286. // the proper USER or GDI handle representation.
  287. //
  288. // history: Dec-95 Ryszardk Created.
  289. // Dec-98 Ryszardk Ported to 64b.
  290. // Aug-99 JohnStra Added consistency checks.
  291. //
  292. //--------------------------------------------------------------------------
  293. unsigned char __RPC_FAR * __RPC_USER
  294. WdtpRemotableHandle_UserUnmarshal (
  295. unsigned long * pFlags,
  296. unsigned char * pBuffer,
  297. LONG_PTR * pHandle )
  298. {
  299. unsigned long HandleMarker;
  300. // Get the buffer size and the start of the buffer.
  301. CUserMarshalInfo MarshalInfo( pFlags, pBuffer );
  302. ULONG_PTR BufferSize = MarshalInfo.GetBufferSize();
  303. UCHAR* pBufferStart = MarshalInfo.GetBuffer();
  304. // Align the buffer and save fixup size.
  305. ALIGN( pBuffer, 3 );
  306. ULONG_PTR cbFixup = (ULONG_PTR)(pBuffer - pBufferStart);
  307. // Check for EOB before accessing data.
  308. CHECK_BUFFER_SIZE( BufferSize, cbFixup + (2 * sizeof( ULONG )) );
  309. HandleMarker = *( PULONG_LV_CAST pBuffer)++;
  310. if ( HandleMarker == WDT_HANDLE_MARKER )
  311. *pHandle = *( PLONG_LV_CAST pBuffer)++;
  312. else
  313. RAISE_RPC_EXCEPTION( RPC_S_INVALID_TAG );
  314. return( pBuffer );
  315. }
  316. //+-------------------------------------------------------------------------
  317. //
  318. // Function: WdtpRemotableHandle_UserFree
  319. //
  320. //--------------------------------------------------------------------------
  321. void __RPC_USER
  322. WdtpRemotableHandle_UserFree(
  323. unsigned long * pFlags,
  324. LONG_PTR * pHandle )
  325. {
  326. }
  327. //+-------------------------------------------------------------------------
  328. //
  329. // Function: HWND_UserSize
  330. //
  331. // Synopsis: Sizes an HWND handle.
  332. //
  333. //--------------------------------------------------------------------------
  334. unsigned long __RPC_USER
  335. HWND_UserSize (
  336. unsigned long * pFlags,
  337. unsigned long Offset,
  338. HWND * pH )
  339. {
  340. return WdtpRemotableHandle_UserSize( pFlags, Offset, (LONG_PTR*)pH );
  341. }
  342. //+-------------------------------------------------------------------------
  343. //
  344. // Function: HWND_UserMarshall
  345. //
  346. // Synopsis: Marshalls an HWND handle into the RPC buffer.
  347. //
  348. //--------------------------------------------------------------------------
  349. unsigned char __RPC_FAR * __RPC_USER
  350. HWND_UserMarshal (
  351. unsigned long * pFlags,
  352. unsigned char * pBuffer,
  353. HWND * pH )
  354. {
  355. return WdtpRemotableHandle_UserMarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  356. }
  357. //+-------------------------------------------------------------------------
  358. //
  359. // Function: HWND_UserUnmarshall
  360. //
  361. // Synopsis: Unmarshalls an HWND handle from the RPC buffer.
  362. //
  363. //--------------------------------------------------------------------------
  364. unsigned char __RPC_FAR * __RPC_USER
  365. HWND_UserUnmarshal (
  366. unsigned long * pFlags,
  367. unsigned char * pBuffer,
  368. HWND * pH )
  369. {
  370. return WdtpRemotableHandle_UserUnmarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  371. }
  372. //+-------------------------------------------------------------------------
  373. //
  374. // Function: HWND_UserFree
  375. //
  376. // Synopsis: Shouldn't be called.
  377. //
  378. //--------------------------------------------------------------------------
  379. void __RPC_USER
  380. HWND_UserFree(
  381. unsigned long * pFlags,
  382. HWND * pH )
  383. {
  384. }
  385. //+-------------------------------------------------------------------------
  386. //
  387. // Function: HMENU_UserSize
  388. //
  389. // Synopsis: Sizes an HMENU handle.
  390. //
  391. //--------------------------------------------------------------------------
  392. unsigned long __RPC_USER
  393. HMENU_UserSize (
  394. unsigned long * pFlags,
  395. unsigned long Offset,
  396. HMENU * pH )
  397. {
  398. return WdtpRemotableHandle_UserSize( pFlags, Offset, (LONG_PTR*)pH );
  399. }
  400. //+-------------------------------------------------------------------------
  401. //
  402. // Function: HMENU_UserMarshall
  403. //
  404. // Synopsis: Marshalls an HMENU handle into the RPC buffer.
  405. //
  406. //--------------------------------------------------------------------------
  407. unsigned char __RPC_FAR * __RPC_USER
  408. HMENU_UserMarshal (
  409. unsigned long * pFlags,
  410. unsigned char * pBuffer,
  411. HMENU * pH )
  412. {
  413. return WdtpRemotableHandle_UserMarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  414. }
  415. //+-------------------------------------------------------------------------
  416. //
  417. // Function: HMENU_UserUnmarshall
  418. //
  419. // Synopsis: Unmarshalls an HMENU handle from the RPC buffer.
  420. //
  421. //--------------------------------------------------------------------------
  422. unsigned char __RPC_FAR * __RPC_USER
  423. HMENU_UserUnmarshal (
  424. unsigned long * pFlags,
  425. unsigned char * pBuffer,
  426. HMENU * pH )
  427. {
  428. return WdtpRemotableHandle_UserUnmarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  429. }
  430. //+-------------------------------------------------------------------------
  431. //
  432. // Function: HMENU_UserFree
  433. //
  434. // Synopsis: Free an HMENU.
  435. //
  436. //--------------------------------------------------------------------------
  437. void __RPC_USER
  438. HMENU_UserFree(
  439. unsigned long * pFlags,
  440. HMENU * pH )
  441. {
  442. }
  443. //+-------------------------------------------------------------------------
  444. //
  445. // Function: HACCEL_UserSize
  446. //
  447. // Synopsis: Sizes an HACCEL handle.
  448. //
  449. //--------------------------------------------------------------------------
  450. unsigned long __RPC_USER
  451. HACCEL_UserSize (
  452. unsigned long * pFlags,
  453. unsigned long Offset,
  454. HACCEL * pH )
  455. {
  456. return WdtpRemotableHandle_UserSize( pFlags, Offset, (LONG_PTR*)pH );
  457. }
  458. //+-------------------------------------------------------------------------
  459. //
  460. // Function: HACCEL_UserMarshall
  461. //
  462. // Synopsis: Marshalls an HACCEL handle into the RPC buffer.
  463. //
  464. //--------------------------------------------------------------------------
  465. unsigned char __RPC_FAR * __RPC_USER
  466. HACCEL_UserMarshal (
  467. unsigned long * pFlags,
  468. unsigned char * pBuffer,
  469. HACCEL * pH )
  470. {
  471. return WdtpRemotableHandle_UserMarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  472. }
  473. //+-------------------------------------------------------------------------
  474. //
  475. // Function: HACCEL_UserUnmarshall
  476. //
  477. // Synopsis: Unmarshalls an HACCEL handle from the RPC buffer.
  478. //
  479. //--------------------------------------------------------------------------
  480. unsigned char __RPC_FAR * __RPC_USER
  481. HACCEL_UserUnmarshal (
  482. unsigned long * pFlags,
  483. unsigned char * pBuffer,
  484. HACCEL * pH )
  485. {
  486. return WdtpRemotableHandle_UserUnmarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  487. }
  488. //+-------------------------------------------------------------------------
  489. //
  490. // Function: HACCEL_UserFree
  491. //
  492. // Synopsis: Free an HACCEL.
  493. //
  494. //--------------------------------------------------------------------------
  495. void __RPC_USER
  496. HACCEL_UserFree(
  497. unsigned long * pFlags,
  498. HACCEL * pH )
  499. {
  500. }
  501. //+-------------------------------------------------------------------------
  502. //
  503. // Function: HBRUSH_UserSize
  504. //
  505. // Synopsis: Sizes an HBRUSH handle.
  506. //
  507. //--------------------------------------------------------------------------
  508. unsigned long __RPC_USER
  509. HBRUSH_UserSize (
  510. unsigned long * pFlags,
  511. unsigned long Offset,
  512. HBRUSH * pH )
  513. {
  514. return WdtpRemotableHandle_UserSize( pFlags, Offset, (LONG_PTR*)pH );
  515. }
  516. //+-------------------------------------------------------------------------
  517. //
  518. // Function: HBRUSH_UserMarshall
  519. //
  520. // Synopsis: Marshalls an HBRUSH handle into the RPC buffer.
  521. //
  522. //--------------------------------------------------------------------------
  523. unsigned char __RPC_FAR * __RPC_USER
  524. HBRUSH_UserMarshal (
  525. unsigned long * pFlags,
  526. unsigned char * pBuffer,
  527. HBRUSH * pH )
  528. {
  529. return WdtpRemotableHandle_UserMarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  530. }
  531. //+-------------------------------------------------------------------------
  532. //
  533. // Function: HBRUSH_UserUnmarshall
  534. //
  535. // Synopsis: Unmarshalls an HBRUSH handle from the RPC buffer.
  536. //
  537. //--------------------------------------------------------------------------
  538. unsigned char __RPC_FAR * __RPC_USER
  539. HBRUSH_UserUnmarshal (
  540. unsigned long * pFlags,
  541. unsigned char * pBuffer,
  542. HBRUSH * pH )
  543. {
  544. return WdtpRemotableHandle_UserUnmarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  545. }
  546. //+-------------------------------------------------------------------------
  547. //
  548. // Function: HBRUSH_UserFree
  549. //
  550. // Synopsis: Free an HBRUSH.
  551. //
  552. //--------------------------------------------------------------------------
  553. void __RPC_USER
  554. HBRUSH_UserFree(
  555. unsigned long * pFlags,
  556. HBRUSH * pH )
  557. {
  558. }
  559. //+-------------------------------------------------------------------------
  560. //
  561. // Function: HICON_UserSize
  562. //
  563. // Synopsis: Sizes an HICON handle.
  564. //
  565. //--------------------------------------------------------------------------
  566. unsigned long __RPC_USER
  567. HICON_UserSize (
  568. unsigned long * pFlags,
  569. unsigned long Offset,
  570. HICON * pH )
  571. {
  572. return WdtpRemotableHandle_UserSize( pFlags, Offset, (LONG_PTR*)pH );
  573. }
  574. //+-------------------------------------------------------------------------
  575. //
  576. // Function: HICON_UserMarshall
  577. //
  578. // Synopsis: Marshalls an HICON handle into the RPC buffer.
  579. //
  580. //--------------------------------------------------------------------------
  581. unsigned char __RPC_FAR * __RPC_USER
  582. HICON_UserMarshal (
  583. unsigned long * pFlags,
  584. unsigned char * pBuffer,
  585. HICON * pH )
  586. {
  587. return WdtpRemotableHandle_UserMarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  588. }
  589. //+-------------------------------------------------------------------------
  590. //
  591. // Function: HICON_UserUnmarshall
  592. //
  593. // Synopsis: Unmarshalls an HICON handle from the RPC buffer.
  594. //
  595. //--------------------------------------------------------------------------
  596. unsigned char __RPC_FAR * __RPC_USER
  597. HICON_UserUnmarshal (
  598. unsigned long * pFlags,
  599. unsigned char * pBuffer,
  600. HICON * pH )
  601. {
  602. return WdtpRemotableHandle_UserUnmarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  603. }
  604. //+-------------------------------------------------------------------------
  605. //
  606. // Function: HICON_UserFree
  607. //
  608. // Synopsis: Free an HICON.
  609. //
  610. //--------------------------------------------------------------------------
  611. void __RPC_USER
  612. HICON_UserFree(
  613. unsigned long * pFlags,
  614. HICON * pH )
  615. {
  616. }
  617. //+-------------------------------------------------------------------------
  618. //
  619. // Function: HDC_UserSize
  620. //
  621. // Synopsis: Sizes an HDC handle.
  622. //
  623. //--------------------------------------------------------------------------
  624. unsigned long __RPC_USER
  625. HDC_UserSize (
  626. unsigned long * pFlags,
  627. unsigned long Offset,
  628. HDC * pH )
  629. {
  630. return WdtpRemotableHandle_UserSize( pFlags, Offset, (LONG_PTR*)pH );
  631. }
  632. //+-------------------------------------------------------------------------
  633. //
  634. // Function: HDC_UserMarshall
  635. //
  636. // Synopsis: Marshalls an HICON handle into the RPC buffer.
  637. //
  638. //--------------------------------------------------------------------------
  639. unsigned char __RPC_FAR * __RPC_USER
  640. HDC_UserMarshal (
  641. unsigned long * pFlags,
  642. unsigned char * pBuffer,
  643. HDC * pH )
  644. {
  645. return WdtpRemotableHandle_UserMarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  646. }
  647. //+-------------------------------------------------------------------------
  648. //
  649. // Function: HDC_UserUnmarshall
  650. //
  651. // Synopsis: Unmarshalls an HICON handle from the RPC buffer.
  652. //
  653. //--------------------------------------------------------------------------
  654. unsigned char __RPC_FAR * __RPC_USER
  655. HDC_UserUnmarshal (
  656. unsigned long * pFlags,
  657. unsigned char * pBuffer,
  658. HDC * pH )
  659. {
  660. return WdtpRemotableHandle_UserUnmarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  661. }
  662. //+-------------------------------------------------------------------------
  663. //
  664. // Function: HDC_UserFree
  665. //
  666. // Synopsis: Free an HDC.
  667. //
  668. //--------------------------------------------------------------------------
  669. void __RPC_USER
  670. HDC_UserFree(
  671. unsigned long * pFlags,
  672. HDC * pH )
  673. {
  674. }
  675. // #########################################################################
  676. //
  677. // Interface pointers.
  678. //
  679. // #########################################################################
  680. //+-------------------------------------------------------------------------
  681. //
  682. // Function: WdtpInterfacePointer_UserSize
  683. //
  684. // Synopsis: Get the wire size for an interface pointer.
  685. //
  686. // history: May-95 Ryszardk Created.
  687. //
  688. //--------------------------------------------------------------------------
  689. EXTERN_C unsigned long __RPC_USER __stdcall
  690. WdtpInterfacePointer_UserSize (
  691. USER_MARSHAL_CB * pContext,
  692. unsigned long Flags,
  693. unsigned long Offset,
  694. IUnknown * pIf,
  695. const IID & IId )
  696. {
  697. if ( pIf )
  698. {
  699. LENGTH_ALIGN( Offset, 3 );
  700. //Leave space for array bounds and length
  701. Offset += 2 * sizeof(long);
  702. HRESULT hr;
  703. unsigned long cbSize = 0;
  704. hr = CoGetMarshalSizeMax( &cbSize,
  705. IId,
  706. pIf,
  707. USER_CALL_CTXT_MASK( Flags ),
  708. pContext->pStubMsg->pvDestContext,
  709. MSHLFLAGS_NORMAL );
  710. if ( FAILED(hr) )
  711. RAISE_RPC_EXCEPTION( hr );
  712. Offset += cbSize;
  713. }
  714. return( Offset ) ;
  715. }
  716. //+-------------------------------------------------------------------------
  717. //
  718. // Function: WdtpInterfacePointer_UserMarshal
  719. //
  720. // Synopsis: Marshalls an interface pointer.
  721. //
  722. // history: May-95 Ryszardk Created.
  723. //
  724. //--------------------------------------------------------------------------
  725. EXTERN_C unsigned char __RPC_FAR * __RPC_USER __stdcall
  726. WdtpInterfacePointer_UserMarshal (
  727. USER_MARSHAL_CB * pContext,
  728. unsigned long Flags,
  729. unsigned char * pBuffer,
  730. IUnknown * pIf,
  731. const IID & IId )
  732. {
  733. unsigned long * pMaxCount, *pSize;
  734. unsigned long cbData = 0;
  735. UserNdrDebugOut((UNDR_OUT1, "WdtpInterface_PointerMarshal\n"));
  736. if ( pIf )
  737. {
  738. // Always marshaled because of the apartment model.
  739. CStreamOnMessage MemStream( (unsigned char **) &pBuffer );
  740. ALIGN( pBuffer, 3 );
  741. pMaxCount = (unsigned long *) pBuffer;
  742. pBuffer += 4;
  743. // Leave space for length
  744. pSize = (unsigned long *) pBuffer;
  745. pBuffer += 4;
  746. HRESULT hr;
  747. unsigned char * pBufferMark = pBuffer;
  748. hr = CoMarshalInterface( &MemStream,
  749. IId,
  750. pIf,
  751. USER_CALL_CTXT_MASK( Flags ),
  752. pContext->pStubMsg->pvDestContext,
  753. MSHLFLAGS_NORMAL );
  754. if( FAILED(hr) )
  755. {
  756. RpcRaiseException(hr);
  757. }
  758. // Calculate the size of the data written
  759. DWORD cbData = (ULONG) (pBuffer - pBufferMark);
  760. // Update the array bounds.
  761. *pMaxCount = cbData;
  762. *pSize = cbData;
  763. }
  764. return( pBuffer );
  765. }
  766. //+-------------------------------------------------------------------------
  767. //
  768. // Function: WdtpInterfacePointer_UserUnmarshalWorker
  769. //
  770. // Synopsis: Unmarshalls an interface pointer from the RPC buffer.
  771. //
  772. // history: Aug-99 JohnStra Created.
  773. // Oct-00 ScottRob/
  774. // YongQu NDR64 Support.
  775. //
  776. //--------------------------------------------------------------------------
  777. unsigned char __RPC_FAR * __RPC_USER
  778. WdtpInterfacePointer_UserUnmarshalWorker (
  779. USER_MARSHAL_CB * pContext,
  780. unsigned char * pBuffer,
  781. IUnknown ** ppIf,
  782. const IID & IId,
  783. ULONG_PTR BufferSize,
  784. BOOL fNDR64 )
  785. {
  786. unsigned long *pMaxCount, *pSize;
  787. unsigned long cbData = 0;
  788. // Align the buffer and save the fixup size.
  789. UCHAR* pBufferStart = pBuffer;
  790. if (fNDR64) ALIGN(pBuffer, 7); else ALIGN( pBuffer, 3 );
  791. ULONG_PTR cbFixup = (ULONG_PTR)(pBuffer - pBufferStart);
  792. // Check for EOB before accessing data.
  793. int cbHeader = (int)((fNDR64) ? 3*sizeof( ULONG ) : 2*sizeof( ULONG ));
  794. CHECK_BUFFER_SIZE( BufferSize, cbFixup + cbHeader + 2*sizeof( ULONG ) + sizeof( GUID ) );
  795. UserNdrDebugOut((UNDR_OUT1, "WdtpInterfacePointerUnmarshal\n"));
  796. pMaxCount = (unsigned long *) pBuffer;
  797. pBuffer += sizeof(long);
  798. if (fNDR64) pBuffer += sizeof(long); //NDR64 Padding
  799. //Unmarshal count
  800. pSize = (unsigned long *) pBuffer;
  801. pBuffer += sizeof(long);
  802. // max count and unmarshal count must be the same.
  803. if ( *pSize != *pMaxCount )
  804. RAISE_RPC_EXCEPTION( RPC_X_BAD_STUB_DATA );
  805. // Get IID from the OBJREF and verify that it matches the supplied IID.
  806. IID* piid;
  807. if( FAILED( GetIIDFromObjRef( *(OBJREF *)pBuffer, &piid ) ) )
  808. RAISE_RPC_EXCEPTION( RPC_X_BAD_STUB_DATA );
  809. if( 0 != memcmp( &IId, piid, sizeof(IID) ) )
  810. RAISE_RPC_EXCEPTION( RPC_X_BAD_STUB_DATA );
  811. // Check for EOB before unmarshaling.
  812. CHECK_BUFFER_SIZE( BufferSize, cbFixup + cbHeader + *pSize );
  813. // Release the old pointer after unmarshalling the new one
  814. // to prevent object from getting released too early.
  815. // Then release the old one only when successful.
  816. IUnknown * punkTemp = 0;
  817. //CodeReview: The original code
  818. // CNdrStream MemStream( pBuffer,
  819. // (ULONG) BufferSize + (2 * sizeof(ULONG)) + *pSize );
  820. // Doesn't look right... We just verified that BufferSize was large enough to
  821. // hold the data. Then we tell the CNdrStream that the size of buffer is double
  822. // that size when we should be only unmarshaling pSize bytes.
  823. // Is this to prevent CoUnmarshalInterface from running up against the end of a corrupted stream?
  824. // Use a CNdrStream for unmarshaling because it checks for buffer overruns.
  825. CNdrStream MemStream( pBuffer,
  826. (ULONG) *pSize );
  827. HRESULT hr = CoUnmarshalInterface( &MemStream,
  828. IId,
  829. (void **) &punkTemp );
  830. if(FAILED(hr))
  831. {
  832. RAISE_RPC_EXCEPTION(hr);
  833. }
  834. else
  835. {
  836. // Get the number of bytes read from the stream.
  837. LARGE_INTEGER lOffset = { 0, 0 };
  838. ULARGE_INTEGER ulCurPos;
  839. hr = MemStream.Seek( lOffset, STREAM_SEEK_CUR, &ulCurPos );
  840. if ( FAILED(hr) )
  841. RAISE_RPC_EXCEPTION( hr );
  842. // Make sure the number of bytes read is what we expected.
  843. if ( ulCurPos.LowPart != *pSize )
  844. RAISE_RPC_EXCEPTION( RPC_X_BAD_STUB_DATA );
  845. // Increment pBuffer pointer by the amount we unmarshaled from it.
  846. pBuffer += ulCurPos.LowPart;
  847. // On the client side, release the [in,out] interface pointer.
  848. // The pointer may be different from NULL only on the client side.
  849. // release the old one, keep the new one.
  850. if ( *ppIf )
  851. (*ppIf)->Release();
  852. *ppIf = punkTemp;
  853. }
  854. return( pBuffer );
  855. }
  856. //+-------------------------------------------------------------------------
  857. //
  858. // Function: WdtpInterfacePointer_UserUnmarshal
  859. //
  860. // Synopsis: Unmarshalls an interface pointer from the RPC buffer.
  861. //
  862. // history: May-95 Ryszardk Created.
  863. // Aug-99 JohnStra Factored bulk of work out into
  864. // worker routine in order to add
  865. // consistency checks.
  866. //
  867. //--------------------------------------------------------------------------
  868. EXTERN_C unsigned char __RPC_FAR * __RPC_USER __stdcall
  869. WdtpInterfacePointer_UserUnmarshal (
  870. USER_MARSHAL_CB * pContext,
  871. unsigned char * pBuffer,
  872. IUnknown ** ppIf,
  873. const IID & IId )
  874. {
  875. // Get the buffer size and the start of the buffer.
  876. CUserMarshalInfo MarshalInfo( (ULONG*)pContext, pBuffer );
  877. ULONG_PTR BufferSize = MarshalInfo.GetBufferSize();
  878. UCHAR* pBufferStart = MarshalInfo.GetBuffer();
  879. // Delegate to worker routine.
  880. pBuffer = WdtpInterfacePointer_UserUnmarshalWorker( pContext,
  881. pBufferStart,
  882. ppIf,
  883. IId,
  884. BufferSize,
  885. FALSE );
  886. return( pBuffer );
  887. }
  888. //+-------------------------------------------------------------------------
  889. //
  890. // Function: WdtpInterfacePointer_UserFree
  891. //
  892. // Synopsis: Releases an interface pointer.
  893. //
  894. // history: May-95 Ryszardk Created.
  895. //
  896. //--------------------------------------------------------------------------
  897. EXTERN_C void __RPC_USER __stdcall
  898. WdtpInterfacePointer_UserFree(
  899. IUnknown * pIf )
  900. {
  901. UserNdrDebugOut((UNDR_OUT1, "WdtpInterfacePointer_UserFree\n"));
  902. if( pIf )
  903. {
  904. pIf->Release();
  905. }
  906. }
  907. #if (DBG==1)
  908. //+-------------------------------------------------------------------------
  909. //
  910. // Function: WdtpGetStgmedName
  911. //
  912. // Synopsis: Debug support
  913. //
  914. // history: May-95 Ryszardk Created.
  915. //
  916. //--------------------------------------------------------------------------
  917. char *
  918. WdtpGetStgmedName( STGMEDIUM * pStgmed)
  919. {
  920. char * Name;
  921. if ( pStgmed )
  922. {
  923. switch (pStgmed->tymed)
  924. {
  925. case TYMED_NULL:
  926. Name = "TYMED_NULL";
  927. break;
  928. case TYMED_MFPICT:
  929. Name = "TYMED_MFPICT";
  930. break;
  931. case TYMED_ENHMF:
  932. Name = "TYMED_ENHMF";
  933. break;
  934. case TYMED_GDI:
  935. Name = "TYMED_GDI";
  936. break;
  937. case TYMED_HGLOBAL:
  938. Name = "TYMED_HGLOBAL";
  939. break;
  940. case TYMED_FILE:
  941. Name = "TYMED_FILE";
  942. break;
  943. case TYMED_ISTREAM:
  944. Name = "TYMED_ISTREAM";
  945. break;
  946. case TYMED_ISTORAGE:
  947. Name = "TYMED_ISTORAGE";
  948. break;
  949. default:
  950. Name = "TYMED invalid";
  951. break;
  952. }
  953. return Name;
  954. }
  955. else
  956. return "STGMED * is null";
  957. }
  958. #endif
  959. //+-------------------------------------------------------------------------
  960. //
  961. // Class: CContinue
  962. //
  963. // Synopsis: Notification object
  964. //
  965. //--------------------------------------------------------------------------
  966. class CContinue : public IContinue
  967. {
  968. private:
  969. long _cRef;
  970. BOOL (__stdcall *_pfnContinue)(LONG_PTR);
  971. LONG_PTR _dwContinue;
  972. ~CContinue(void);
  973. public:
  974. CContinue(BOOL (__stdcall *pfnContinue)(LONG_PTR dwContinue), LONG_PTR dwContinue);
  975. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void **);
  976. ULONG STDMETHODCALLTYPE AddRef();
  977. ULONG STDMETHODCALLTYPE Release();
  978. HRESULT STDMETHODCALLTYPE FContinue();
  979. };
  980. //+-------------------------------------------------------------------------
  981. //
  982. // Method: CContinue::CContinue, public
  983. //
  984. // Synopsis: Constructor for CContinue
  985. //
  986. //--------------------------------------------------------------------------
  987. CContinue::CContinue(BOOL (__stdcall *pfnContinue)(LONG_PTR dwContinue), LONG_PTR dwContinue)
  988. : _cRef(1), _pfnContinue(pfnContinue), _dwContinue(dwContinue)
  989. {
  990. }
  991. CContinue::~CContinue()
  992. {
  993. }
  994. //+-------------------------------------------------------------------------
  995. //
  996. // Method: CContinue::QueryInterface, public
  997. //
  998. // Synopsis: Query for an interface on the notification object.
  999. //
  1000. //--------------------------------------------------------------------------
  1001. HRESULT STDMETHODCALLTYPE
  1002. CContinue::QueryInterface (
  1003. REFIID iid,
  1004. void **ppv )
  1005. {
  1006. HRESULT hr = E_NOINTERFACE;
  1007. if ((IID_IUnknown == iid) || (IID_IContinue == iid))
  1008. {
  1009. this->AddRef();
  1010. *ppv = (IContinue *) this;
  1011. hr = S_OK;
  1012. }
  1013. else
  1014. {
  1015. *ppv = 0;
  1016. }
  1017. return hr;
  1018. }
  1019. //+-------------------------------------------------------------------------
  1020. //
  1021. // Method: CContinue::AddRef, public
  1022. //
  1023. // Synopsis: Increment the reference count.
  1024. //
  1025. //--------------------------------------------------------------------------
  1026. ULONG STDMETHODCALLTYPE
  1027. CContinue::AddRef()
  1028. {
  1029. InterlockedIncrement((long *) &_cRef);
  1030. return (unsigned long) _cRef;
  1031. }
  1032. //+-------------------------------------------------------------------------
  1033. //
  1034. // Method: CContinue::Release, public
  1035. //
  1036. // Synopsis: Decrement the reference count.
  1037. //
  1038. //--------------------------------------------------------------------------
  1039. ULONG STDMETHODCALLTYPE
  1040. CContinue::Release()
  1041. {
  1042. unsigned long count = _cRef - 1;
  1043. if(0 == InterlockedDecrement((long *)&_cRef))
  1044. {
  1045. count = 0;
  1046. delete this;
  1047. }
  1048. return count;
  1049. }
  1050. //+-------------------------------------------------------------------------
  1051. //
  1052. // Method: CContinue::FContinue, public
  1053. //
  1054. // Synopsis: Calls the callback function.
  1055. //
  1056. //--------------------------------------------------------------------------
  1057. HRESULT STDMETHODCALLTYPE
  1058. CContinue::FContinue()
  1059. {
  1060. HRESULT hr;
  1061. BOOL bResult;
  1062. bResult = (*_pfnContinue) (_dwContinue);
  1063. if(bResult == FALSE)
  1064. {
  1065. hr = S_FALSE;
  1066. }
  1067. else
  1068. {
  1069. hr = S_OK;
  1070. }
  1071. return hr;
  1072. }
  1073. //+-------------------------------------------------------------------------
  1074. //
  1075. // Function: CreateCallback
  1076. //
  1077. // Synopsis: Create a callback notification object .
  1078. //
  1079. //--------------------------------------------------------------------------
  1080. extern "C" HRESULT CreateCallback(
  1081. BOOL (__stdcall *pfnContinue)(LONG_PTR dwContinue),
  1082. LONG_PTR dwContinue,
  1083. IContinue **ppContinue)
  1084. {
  1085. HRESULT hr;
  1086. if(pfnContinue != 0)
  1087. {
  1088. CContinue *pContinue = new CContinue(pfnContinue, dwContinue);
  1089. *ppContinue = (IContinue *) pContinue;
  1090. if(pContinue != 0)
  1091. {
  1092. hr = S_OK;
  1093. }
  1094. else
  1095. {
  1096. hr = E_OUTOFMEMORY;
  1097. }
  1098. }
  1099. else
  1100. {
  1101. hr = E_INVALIDARG;
  1102. *ppContinue = 0;
  1103. }
  1104. return hr;
  1105. }
  1106. ////// NDR64 funcs
  1107. #ifdef _WIN64
  1108. //+-------------------------------------------------------------------------
  1109. //
  1110. // Function: HWND_UserSize
  1111. //
  1112. // Synopsis: Sizes an HWND handle.
  1113. //
  1114. //--------------------------------------------------------------------------
  1115. unsigned long __RPC_USER
  1116. HWND_UserSize64 (
  1117. unsigned long * pFlags,
  1118. unsigned long Offset,
  1119. HWND * pH )
  1120. {
  1121. return WdtpRemotableHandle_UserSize( pFlags, Offset, (LONG_PTR*)pH );
  1122. }
  1123. //+-------------------------------------------------------------------------
  1124. //
  1125. // Function: HWND_UserMarshall
  1126. //
  1127. // Synopsis: Marshalls an HWND handle into the RPC buffer.
  1128. //
  1129. //--------------------------------------------------------------------------
  1130. unsigned char __RPC_FAR * __RPC_USER
  1131. HWND_UserMarshal64 (
  1132. unsigned long * pFlags,
  1133. unsigned char * pBuffer,
  1134. HWND * pH )
  1135. {
  1136. return HWND_UserMarshal( pFlags, pBuffer, pH );
  1137. }
  1138. //+-------------------------------------------------------------------------
  1139. //
  1140. // Function: HWND_UserUnmarshall
  1141. //
  1142. // Synopsis: Unmarshalls an HWND handle from the RPC buffer.
  1143. //
  1144. //--------------------------------------------------------------------------
  1145. unsigned char __RPC_FAR * __RPC_USER
  1146. HWND_UserUnmarshal64 (
  1147. unsigned long * pFlags,
  1148. unsigned char * pBuffer,
  1149. HWND * pH )
  1150. {
  1151. return WdtpRemotableHandle_UserUnmarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  1152. }
  1153. //+-------------------------------------------------------------------------
  1154. //
  1155. // Function: HWND_UserFree
  1156. //
  1157. // Synopsis: Shouldn't be called.
  1158. //
  1159. //--------------------------------------------------------------------------
  1160. void __RPC_USER
  1161. HWND_UserFree64(
  1162. unsigned long * pFlags,
  1163. HWND * pH )
  1164. {
  1165. }
  1166. //+-------------------------------------------------------------------------
  1167. //
  1168. // Function: HMENU_UserSize
  1169. //
  1170. // Synopsis: Sizes an HMENU handle.
  1171. //
  1172. //--------------------------------------------------------------------------
  1173. unsigned long __RPC_USER
  1174. HMENU_UserSize64(
  1175. unsigned long * pFlags,
  1176. unsigned long Offset,
  1177. HMENU * pH )
  1178. {
  1179. return WdtpRemotableHandle_UserSize( pFlags, Offset, (LONG_PTR*)pH );
  1180. }
  1181. //+-------------------------------------------------------------------------
  1182. //
  1183. // Function: HMENU_UserMarshall
  1184. //
  1185. // Synopsis: Marshalls an HMENU handle into the RPC buffer.
  1186. //
  1187. //--------------------------------------------------------------------------
  1188. unsigned char __RPC_FAR * __RPC_USER
  1189. HMENU_UserMarshal64(
  1190. unsigned long * pFlags,
  1191. unsigned char * pBuffer,
  1192. HMENU * pH )
  1193. {
  1194. return WdtpRemotableHandle_UserMarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  1195. }
  1196. //+-------------------------------------------------------------------------
  1197. //
  1198. // Function: HMENU_UserUnmarshall
  1199. //
  1200. // Synopsis: Unmarshalls an HMENU handle from the RPC buffer.
  1201. //
  1202. //--------------------------------------------------------------------------
  1203. unsigned char __RPC_FAR * __RPC_USER
  1204. HMENU_UserUnmarshal64(
  1205. unsigned long * pFlags,
  1206. unsigned char * pBuffer,
  1207. HMENU * pH )
  1208. {
  1209. return WdtpRemotableHandle_UserUnmarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  1210. }
  1211. //+-------------------------------------------------------------------------
  1212. //
  1213. // Function: HMENU_UserFree
  1214. //
  1215. // Synopsis: Free an HMENU.
  1216. //
  1217. //--------------------------------------------------------------------------
  1218. void __RPC_USER
  1219. HMENU_UserFree64(
  1220. unsigned long * pFlags,
  1221. HMENU * pH )
  1222. {
  1223. }
  1224. //+-------------------------------------------------------------------------
  1225. //
  1226. // Function: HACCEL_UserSize
  1227. //
  1228. // Synopsis: Sizes an HACCEL handle.
  1229. //
  1230. //--------------------------------------------------------------------------
  1231. unsigned long __RPC_USER
  1232. HACCEL_UserSize64 (
  1233. unsigned long * pFlags,
  1234. unsigned long Offset,
  1235. HACCEL * pH )
  1236. {
  1237. return WdtpRemotableHandle_UserSize( pFlags, Offset, (LONG_PTR*)pH );
  1238. }
  1239. //+-------------------------------------------------------------------------
  1240. //
  1241. // Function: HACCEL_UserMarshall
  1242. //
  1243. // Synopsis: Marshalls an HACCEL handle into the RPC buffer.
  1244. //
  1245. //--------------------------------------------------------------------------
  1246. unsigned char __RPC_FAR * __RPC_USER
  1247. HACCEL_UserMarshal64 (
  1248. unsigned long * pFlags,
  1249. unsigned char * pBuffer,
  1250. HACCEL * pH )
  1251. {
  1252. return WdtpRemotableHandle_UserMarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  1253. }
  1254. //+-------------------------------------------------------------------------
  1255. //
  1256. // Function: HACCEL_UserUnmarshall
  1257. //
  1258. // Synopsis: Unmarshalls an HACCEL handle from the RPC buffer.
  1259. //
  1260. //--------------------------------------------------------------------------
  1261. unsigned char __RPC_FAR * __RPC_USER
  1262. HACCEL_UserUnmarshal64 (
  1263. unsigned long * pFlags,
  1264. unsigned char * pBuffer,
  1265. HACCEL * pH )
  1266. {
  1267. return WdtpRemotableHandle_UserUnmarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  1268. }
  1269. //+-------------------------------------------------------------------------
  1270. //
  1271. // Function: HACCEL_UserFree
  1272. //
  1273. // Synopsis: Free an HACCEL.
  1274. //
  1275. //--------------------------------------------------------------------------
  1276. void __RPC_USER
  1277. HACCEL_UserFree64(
  1278. unsigned long * pFlags,
  1279. HACCEL * pH )
  1280. {
  1281. }
  1282. //+-------------------------------------------------------------------------
  1283. //
  1284. // Function: HBRUSH_UserSize
  1285. //
  1286. // Synopsis: Sizes an HBRUSH handle.
  1287. //
  1288. //--------------------------------------------------------------------------
  1289. unsigned long __RPC_USER
  1290. HBRUSH_UserSize64(
  1291. unsigned long * pFlags,
  1292. unsigned long Offset,
  1293. HBRUSH * pH )
  1294. {
  1295. return WdtpRemotableHandle_UserSize( pFlags, Offset, (LONG_PTR*)pH );
  1296. }
  1297. //+-------------------------------------------------------------------------
  1298. //
  1299. // Function: HBRUSH_UserMarshall
  1300. //
  1301. // Synopsis: Marshalls an HBRUSH handle into the RPC buffer.
  1302. //
  1303. //--------------------------------------------------------------------------
  1304. unsigned char __RPC_FAR * __RPC_USER
  1305. HBRUSH_UserMarshal64 (
  1306. unsigned long * pFlags,
  1307. unsigned char * pBuffer,
  1308. HBRUSH * pH )
  1309. {
  1310. return WdtpRemotableHandle_UserMarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  1311. }
  1312. //+-------------------------------------------------------------------------
  1313. //
  1314. // Function: HBRUSH_UserUnmarshall
  1315. //
  1316. // Synopsis: Unmarshalls an HBRUSH handle from the RPC buffer.
  1317. //
  1318. //--------------------------------------------------------------------------
  1319. unsigned char __RPC_FAR * __RPC_USER
  1320. HBRUSH_UserUnmarshal64 (
  1321. unsigned long * pFlags,
  1322. unsigned char * pBuffer,
  1323. HBRUSH * pH )
  1324. {
  1325. return WdtpRemotableHandle_UserUnmarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  1326. }
  1327. //+-------------------------------------------------------------------------
  1328. //
  1329. // Function: HBRUSH_UserFree
  1330. //
  1331. // Synopsis: Free an HBRUSH.
  1332. //
  1333. //--------------------------------------------------------------------------
  1334. void __RPC_USER
  1335. HBRUSH_UserFree64(
  1336. unsigned long * pFlags,
  1337. HBRUSH * pH )
  1338. {
  1339. }
  1340. //+-------------------------------------------------------------------------
  1341. //
  1342. // Function: HICON_UserSize
  1343. //
  1344. // Synopsis: Sizes an HICON handle.
  1345. //
  1346. //--------------------------------------------------------------------------
  1347. unsigned long __RPC_USER
  1348. HICON_UserSize64 (
  1349. unsigned long * pFlags,
  1350. unsigned long Offset,
  1351. HICON * pH )
  1352. {
  1353. return WdtpRemotableHandle_UserSize( pFlags, Offset, (LONG_PTR*)pH );
  1354. }
  1355. //+-------------------------------------------------------------------------
  1356. //
  1357. // Function: HICON_UserMarshall
  1358. //
  1359. // Synopsis: Marshalls an HICON handle into the RPC buffer.
  1360. //
  1361. //--------------------------------------------------------------------------
  1362. unsigned char __RPC_FAR * __RPC_USER
  1363. HICON_UserMarshal64 (
  1364. unsigned long * pFlags,
  1365. unsigned char * pBuffer,
  1366. HICON * pH )
  1367. {
  1368. return WdtpRemotableHandle_UserMarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  1369. }
  1370. //+-------------------------------------------------------------------------
  1371. //
  1372. // Function: HICON_UserUnmarshall
  1373. //
  1374. // Synopsis: Unmarshalls an HICON handle from the RPC buffer.
  1375. //
  1376. //--------------------------------------------------------------------------
  1377. unsigned char __RPC_FAR * __RPC_USER
  1378. HICON_UserUnmarshal64 (
  1379. unsigned long * pFlags,
  1380. unsigned char * pBuffer,
  1381. HICON * pH )
  1382. {
  1383. return WdtpRemotableHandle_UserUnmarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  1384. }
  1385. //+-------------------------------------------------------------------------
  1386. //
  1387. // Function: HICON_UserFree
  1388. //
  1389. // Synopsis: Free an HICON.
  1390. //
  1391. //--------------------------------------------------------------------------
  1392. void __RPC_USER
  1393. HICON_UserFree64(
  1394. unsigned long * pFlags,
  1395. HICON * pH )
  1396. {
  1397. }
  1398. //+-------------------------------------------------------------------------
  1399. //
  1400. // Function: HDC_UserSize
  1401. //
  1402. // Synopsis: Sizes an HDC handle.
  1403. //
  1404. //--------------------------------------------------------------------------
  1405. unsigned long __RPC_USER
  1406. HDC_UserSize64 (
  1407. unsigned long * pFlags,
  1408. unsigned long Offset,
  1409. HDC * pH )
  1410. {
  1411. return WdtpRemotableHandle_UserSize( pFlags, Offset, (LONG_PTR*)pH );
  1412. }
  1413. //+-------------------------------------------------------------------------
  1414. //
  1415. // Function: HDC_UserMarshall
  1416. //
  1417. // Synopsis: Marshalls an HICON handle into the RPC buffer.
  1418. //
  1419. //--------------------------------------------------------------------------
  1420. unsigned char __RPC_FAR * __RPC_USER
  1421. HDC_UserMarshal64 (
  1422. unsigned long * pFlags,
  1423. unsigned char * pBuffer,
  1424. HDC * pH )
  1425. {
  1426. return WdtpRemotableHandle_UserMarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  1427. }
  1428. //+-------------------------------------------------------------------------
  1429. //
  1430. // Function: HDC_UserUnmarshall
  1431. //
  1432. // Synopsis: Unmarshalls an HICON handle from the RPC buffer.
  1433. //
  1434. //--------------------------------------------------------------------------
  1435. unsigned char __RPC_FAR * __RPC_USER
  1436. HDC_UserUnmarshal64 (
  1437. unsigned long * pFlags,
  1438. unsigned char * pBuffer,
  1439. HDC * pH )
  1440. {
  1441. return WdtpRemotableHandle_UserUnmarshal( pFlags, pBuffer, (LONG_PTR*)pH );
  1442. }
  1443. //+-------------------------------------------------------------------------
  1444. //
  1445. // Function: HDC_UserFree
  1446. //
  1447. // Synopsis: Free an HDC.
  1448. //
  1449. //--------------------------------------------------------------------------
  1450. void __RPC_USER
  1451. HDC_UserFree64(
  1452. unsigned long * pFlags,
  1453. HDC * pH )
  1454. {
  1455. }
  1456. // #########################################################################
  1457. //
  1458. // Interface pointers.
  1459. //
  1460. // #########################################################################
  1461. //+-------------------------------------------------------------------------
  1462. //
  1463. // Function: WdtpInterfacePointer_UserSize64
  1464. //
  1465. // Synopsis: Get the wire size for an interface pointer.
  1466. //
  1467. // history: Oct-00 ScottRob/
  1468. // YongQu Created for NDR64 Support
  1469. //
  1470. //--------------------------------------------------------------------------
  1471. EXTERN_C unsigned long __RPC_USER __stdcall
  1472. WdtpInterfacePointer_UserSize64 (
  1473. USER_MARSHAL_CB * pContext,
  1474. unsigned long Flags,
  1475. unsigned long Offset,
  1476. IUnknown * pIf,
  1477. const IID & IId )
  1478. {
  1479. if ( pIf )
  1480. {
  1481. LENGTH_ALIGN( Offset, 7 );
  1482. //Leave space for array bounds, padding, and length
  1483. Offset += 3 * sizeof(long);
  1484. HRESULT hr;
  1485. unsigned long cbSize = 0;
  1486. hr = CoGetMarshalSizeMax( &cbSize,
  1487. IId,
  1488. pIf,
  1489. USER_CALL_CTXT_MASK( Flags ),
  1490. pContext->pStubMsg->pvDestContext,
  1491. MSHLFLAGS_NORMAL );
  1492. if ( FAILED(hr) )
  1493. RAISE_RPC_EXCEPTION( hr );
  1494. Offset += cbSize;
  1495. }
  1496. return( Offset ) ;
  1497. }
  1498. //+-------------------------------------------------------------------------
  1499. //
  1500. // Function: WdtpInterfacePointer_UserMarshal64
  1501. //
  1502. // Synopsis: Marshalls an interface pointer.
  1503. //
  1504. // history: Oct-2000 ScottRob/YongQu Created for NDR64.
  1505. //
  1506. //--------------------------------------------------------------------------
  1507. EXTERN_C unsigned char __RPC_FAR * __RPC_USER __stdcall
  1508. WdtpInterfacePointer_UserMarshal64 (
  1509. USER_MARSHAL_CB * pContext,
  1510. unsigned long Flags,
  1511. unsigned char * pBuffer,
  1512. IUnknown * pIf,
  1513. const IID & IId )
  1514. {
  1515. unsigned long * pMaxCount, *pSize;
  1516. unsigned long cbData = 0;
  1517. UserNdrDebugOut((UNDR_OUT1, "WdtpInterface_PointerMarshal64\n"));
  1518. if ( pIf )
  1519. {
  1520. // Always marshaled because of the apartment model.
  1521. CStreamOnMessage MemStream( (unsigned char **) &pBuffer );
  1522. ALIGN( pBuffer, 7 ); // need to align to 8
  1523. pMaxCount = (unsigned long *) pBuffer;
  1524. pBuffer += 2 * sizeof( long ); // conformant size is 8
  1525. // Leave space for length
  1526. pSize = (unsigned long *) pBuffer;
  1527. pBuffer += sizeof( long );
  1528. HRESULT hr;
  1529. unsigned char * pBufferMark = pBuffer;
  1530. hr = CoMarshalInterface( &MemStream,
  1531. IId,
  1532. pIf,
  1533. USER_CALL_CTXT_MASK( Flags ),
  1534. pContext->pStubMsg->pvDestContext,
  1535. MSHLFLAGS_NORMAL );
  1536. if ( FAILED(hr) )
  1537. {
  1538. RpcRaiseException(hr);
  1539. }
  1540. // Calculate the size of the data written
  1541. DWORD cbData = (ULONG) (pBuffer - pBufferMark);
  1542. // Update the array bounds.
  1543. *pMaxCount = cbData;
  1544. *pSize = cbData;
  1545. }
  1546. return( pBuffer );
  1547. }
  1548. //+-------------------------------------------------------------------------
  1549. //
  1550. // Function: WdtpInterfacePointer_UserUnmarshal64
  1551. //
  1552. // Synopsis: Unmarshalls an interface pointer from the RPC buffer.
  1553. //
  1554. // history: Oct-00 ScottRob/
  1555. // YongQu Created for NDR64.
  1556. //
  1557. //--------------------------------------------------------------------------
  1558. EXTERN_C unsigned char __RPC_FAR * __RPC_USER __stdcall
  1559. WdtpInterfacePointer_UserUnmarshal64 (
  1560. USER_MARSHAL_CB * pContext,
  1561. unsigned char * pBuffer,
  1562. IUnknown ** ppIf,
  1563. const IID & IId )
  1564. {
  1565. // Get the buffer size and the start of the buffer.
  1566. CUserMarshalInfo MarshalInfo( (ULONG*)pContext, pBuffer );
  1567. ULONG_PTR BufferSize = MarshalInfo.GetBufferSize();
  1568. UCHAR* pBufferStart = MarshalInfo.GetBuffer();
  1569. // Delegate to worker routine.
  1570. pBuffer = WdtpInterfacePointer_UserUnmarshalWorker( pContext,
  1571. pBufferStart,
  1572. ppIf,
  1573. IId,
  1574. BufferSize,
  1575. TRUE );
  1576. return( pBuffer );
  1577. }
  1578. //+-------------------------------------------------------------------------
  1579. //
  1580. // Function: WdtpInterfacePointer_UserFree64
  1581. //
  1582. // Synopsis: Frees the unmarshaled interface
  1583. //
  1584. // history: Oct-2000 ScottRob/YongQu Created for NDR64.
  1585. //
  1586. //--------------------------------------------------------------------------
  1587. EXTERN_C void __RPC_USER __stdcall
  1588. WdtpInterfacePointer_UserFree64(
  1589. IUnknown * pIf )
  1590. {
  1591. WdtpInterfacePointer_UserFree(pIf);
  1592. }
  1593. #endif // _WIN64