update dev300-m58
[ooovba.git] / dtrans / source / win32 / workbench / testmarshal.cxx
blob052a1b571f93c5d7a19319b0d5192d69ec70845a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testmarshal.cxx,v $
10 * $Revision: 1.8 $
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 //_________________________________________________________________________________________________________________________
36 // interface includes
37 //_________________________________________________________________________________________________________________________
39 //_________________________________________________________________________________________________________________________
40 // other includes
41 //_________________________________________________________________________________________________________________________
42 #include <rtl/ustring.hxx>
43 #include <sal/types.h>
44 #include <osl/diagnose.h>
46 #include <stdio.h>
47 #if defined _MSC_VER
48 #pragma warning(push,1)
49 #endif
50 #include <windows.h>
51 #include <objbase.h>
52 #if defined _MSC_VER
53 #pragma warning(pop)
54 #endif
56 #include <memory>
58 #include <process.h>
59 #include "XTDo.hxx"
61 //-------------------------------------------------------------
62 // my defines
63 //-------------------------------------------------------------
65 #define WRITE_CB
66 #define EVT_MANUAL_RESET TRUE
67 #define EVT_INIT_NONSIGNALED FALSE
68 #define EVT_NONAME ""
69 #define WAIT_MSGLOOP
70 #define RAW_MARSHALING
72 //------------------------------------------------------------
73 // namesapces
74 //------------------------------------------------------------
76 using namespace ::rtl;
77 using namespace ::std;
79 //------------------------------------------------------------
80 // globales
81 //------------------------------------------------------------
83 HANDLE g_hEvtThreadWakeup;
85 #ifdef RAW_MARSHALING
86 HGLOBAL g_hGlob;
87 #else
88 IStream* g_pStm;
89 #endif
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 );
101 IDataObject* pIDo;
103 #ifdef RAW_MARSHALING
105 IStream* pStm = NULL;
106 hr = CreateStreamOnHGlobal( g_hGlob, FALSE, &pStm );
107 if ( SUCCEEDED( hr ) )
109 hr = CoUnmarshalInterface(
110 pStm,
111 __uuidof( IDataObject ),
112 (void**)&pIDo );
114 hr = pStm->Release( );
117 #else
119 hr = CoGetInterfaceAndReleaseStream(
120 g_pStm,
121 __uuidof( IDataObject ),
122 (void**)&pIDo
125 #endif
127 IEnumFORMATETC* pIEEtc;
128 hr = pIDo->EnumFormatEtc( DATADIR_GET, &pIEEtc );
130 hr = OleIsCurrentClipboard( pIDo );
132 hr = OleFlushClipboard( );
134 OleUninitialize( );
136 return 0;
139 //################################################################
141 //----------------------------------------------------------------
142 // main
143 //----------------------------------------------------------------
145 int SAL_CALL main( int nArgc, char* Argv[] )
147 HRESULT hr = OleInitialize( NULL );
149 g_hEvtThreadWakeup = CreateEvent( 0,
150 EVT_MANUAL_RESET,
151 EVT_INIT_NONSIGNALED,
152 EVT_NONAME );
154 unsigned uThreadId;
155 HANDLE hThread;
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 );
163 hr = E_FAIL;
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(
178 pStm,
179 __uuidof( IDataObject ),
180 pIDo,
181 MSHCTX_INPROC,
183 MSHLFLAGS_NORMAL );
184 if ( SUCCEEDED( hr ) )
185 hr = GetHGlobalFromStream( pStm, &g_hGlob );
187 hr = pStm->Release( );
190 #else
192 hr = CoMarshalInterThreadInterfaceInStream(
193 __uuidof( IDataObject ),
194 pIDo,
195 &g_pStm );
197 #endif
199 if ( SUCCEEDED( hr ) )
201 // wakeup the thread and waiting util it ends
202 SetEvent( g_hEvtThreadWakeup );
204 #ifdef WAIT_MSGLOOP
206 BOOL bContinue = TRUE;
208 while( bContinue )
210 DWORD dwResult = WaitForMultipleObjects(
212 &hThread,
213 TRUE,
214 0 );
216 if ( WAIT_OBJECT_0 == dwResult )
218 bContinue = FALSE;
220 else
222 MSG msg;
223 while( PeekMessage(
224 &msg,
225 NULL,
228 PM_REMOVE ) )
230 TranslateMessage(&msg);
231 DispatchMessage(&msg);
234 } // while
236 #endif
238 } // if
239 } // if
241 OleFlushClipboard( );
243 OleUninitialize( );
245 return 0;