1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testmarshal.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dtrans.hxx"
35 //_________________________________________________________________________________________________________________________
37 //_________________________________________________________________________________________________________________________
39 //_________________________________________________________________________________________________________________________
41 //_________________________________________________________________________________________________________________________
42 #include <rtl/ustring.hxx>
43 #include <sal/types.h>
44 #include <osl/diagnose.h>
48 #pragma warning(push,1)
61 //-------------------------------------------------------------
63 //-------------------------------------------------------------
66 #define EVT_MANUAL_RESET TRUE
67 #define EVT_INIT_NONSIGNALED FALSE
70 #define RAW_MARSHALING
72 //------------------------------------------------------------
74 //------------------------------------------------------------
76 using namespace ::rtl
;
77 using namespace ::std
;
79 //------------------------------------------------------------
81 //------------------------------------------------------------
83 HANDLE g_hEvtThreadWakeup
;
91 //################################################################
92 // a thread in another apartment to test apartment transparency
94 unsigned int _stdcall
ThreadProc(LPVOID pParam
)
96 // setup another apartment
97 HRESULT hr
= OleInitialize( NULL
);
99 WaitForSingleObject( g_hEvtThreadWakeup
, INFINITE
);
103 #ifdef RAW_MARSHALING
105 IStream
* pStm
= NULL
;
106 hr
= CreateStreamOnHGlobal( g_hGlob
, FALSE
, &pStm
);
107 if ( SUCCEEDED( hr
) )
109 hr
= CoUnmarshalInterface(
111 __uuidof( IDataObject
),
114 hr
= pStm
->Release( );
119 hr
= CoGetInterfaceAndReleaseStream(
121 __uuidof( IDataObject
),
127 IEnumFORMATETC
* pIEEtc
;
128 hr
= pIDo
->EnumFormatEtc( DATADIR_GET
, &pIEEtc
);
130 hr
= OleIsCurrentClipboard( pIDo
);
132 hr
= OleFlushClipboard( );
139 //################################################################
141 //----------------------------------------------------------------
143 //----------------------------------------------------------------
145 int SAL_CALL
main( int nArgc
, char* Argv
[] )
147 HRESULT hr
= OleInitialize( NULL
);
149 g_hEvtThreadWakeup
= CreateEvent( 0,
151 EVT_INIT_NONSIGNALED
,
157 // create a thread in another apartment
158 hThread
= (void*)_beginthreadex( NULL
, 0, ThreadProc
, NULL
, 0, &uThreadId
);
160 IDataObject
* pIDo
= new CXTDataObject( );
162 hr
= OleSetClipboard( pIDo
);
165 hr
= OleIsCurrentClipboard( pIDo
);
167 //hr = OleGetClipboard( &pIDo );
168 if ( SUCCEEDED( hr
) )
170 #ifdef RAW_MARSHALING
172 IStream
* pStm
= NULL
;
174 hr
= CreateStreamOnHGlobal( 0, FALSE
, &pStm
);
175 if ( SUCCEEDED( hr
) )
177 hr
= CoMarshalInterface(
179 __uuidof( IDataObject
),
184 if ( SUCCEEDED( hr
) )
185 hr
= GetHGlobalFromStream( pStm
, &g_hGlob
);
187 hr
= pStm
->Release( );
192 hr
= CoMarshalInterThreadInterfaceInStream(
193 __uuidof( IDataObject
),
199 if ( SUCCEEDED( hr
) )
201 // wakeup the thread and waiting util it ends
202 SetEvent( g_hEvtThreadWakeup
);
206 BOOL bContinue
= TRUE
;
210 DWORD dwResult
= WaitForMultipleObjects(
216 if ( WAIT_OBJECT_0
== dwResult
)
230 TranslateMessage(&msg
);
231 DispatchMessage(&msg
);
241 OleFlushClipboard( );