1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 
25 #ifndef _APNDATAOBJECT_HXX_
26 #define _APNDATAOBJECT_HXX_
27 
28 //------------------------------------------------------------------------
29 // deklarations
30 //------------------------------------------------------------------------
31 
32 /*
33 	an APartment Neutral dataobject wrapper; this wrapper of a IDataObject
34 	pointer can be used from any apartment without RPC_E_WRONG_THREAD
35 	which normally occurs if an apartment tries to use an interface
36 	pointer of another apartment; we use containment to hold the original
37 	DataObject
38 */
39 class CAPNDataObject : public IDataObject
40 {
41 public:
42 	CAPNDataObject( IDataObjectPtr rIDataObject );
43 	~CAPNDataObject( );
44 
45 	//-----------------------------------------------------------------
46     //IUnknown interface methods
47 	//-----------------------------------------------------------------
48 
49     STDMETHODIMP           QueryInterface(REFIID iid, LPVOID* ppvObject);
50     STDMETHODIMP_( ULONG ) AddRef( );
51     STDMETHODIMP_( ULONG ) Release( );
52 
53 	//-----------------------------------------------------------------
54     // IDataObject interface methods
55 	//-----------------------------------------------------------------
56 
57     STDMETHODIMP GetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium );
58     STDMETHODIMP GetDataHere( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium );
59     STDMETHODIMP QueryGetData( LPFORMATETC pFormatetc );
60     STDMETHODIMP GetCanonicalFormatEtc( LPFORMATETC pFormatectIn, LPFORMATETC pFormatetcOut );
61     STDMETHODIMP SetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium, BOOL fRelease );
62     STDMETHODIMP EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC** ppenumFormatetc );
63     STDMETHODIMP DAdvise( LPFORMATETC pFormatetc, DWORD advf, LPADVISESINK pAdvSink, DWORD* pdwConnection );
64     STDMETHODIMP DUnadvise( DWORD dwConnection );
65     STDMETHODIMP EnumDAdvise( LPENUMSTATDATA* ppenumAdvise );
66 
67 	operator IDataObject*( );
68 
69 private:
70 	HRESULT MarshalIDataObjectIntoCurrentApartment( IDataObject** ppIDataObj );
71 
72 private:
73 	IDataObjectPtr  m_rIDataObjectOrg;
74 	HGLOBAL			m_hGlobal;
75 	LONG			m_nRefCnt;
76 
77 // prevent copy and assignment
78 private:
79 	CAPNDataObject( const CAPNDataObject& theOther );
80 	CAPNDataObject& operator=( const CAPNDataObject& theOther );
81 };
82 
83 #endif
84