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.

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