fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dtrans / source / win32 / workbench / testmarshal.cxx
blobb3fd58f61bdad70d8685214347280dc99c38a7c4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <rtl/ustring.hxx>
21 #include <sal/types.h>
22 #include <osl/diagnose.h>
24 #include <stdio.h>
25 #if defined _MSC_VER
26 #pragma warning(push,1)
27 #endif
28 #include <windows.h>
29 #include <objbase.h>
30 #if defined _MSC_VER
31 #pragma warning(pop)
32 #endif
34 #include <memory>
36 #include <process.h>
37 #include "XTDo.hxx"
39 // my defines
41 #define WRITE_CB
42 #define EVT_MANUAL_RESET TRUE
43 #define EVT_INIT_NONSIGNALED FALSE
44 #define EVT_NONAME ""
45 #define WAIT_MSGLOOP
46 #define RAW_MARSHALING
48 // namesapces
50 using namespace ::std;
52 // globales
54 HANDLE g_hEvtThreadWakeup;
56 #ifdef RAW_MARSHALING
57 HGLOBAL g_hGlob;
58 #else
59 IStream* g_pStm;
60 #endif
62 // a thread in another apartment to test apartment transparency
64 unsigned int _stdcall ThreadProc(LPVOID pParam)
66 // setup another apartment
67 HRESULT hr = OleInitialize( NULL );
69 WaitForSingleObject( g_hEvtThreadWakeup, INFINITE );
71 IDataObject* pIDo;
73 #ifdef RAW_MARSHALING
75 IStream* pStm = NULL;
76 hr = CreateStreamOnHGlobal( g_hGlob, FALSE, &pStm );
77 if ( SUCCEEDED( hr ) )
79 hr = CoUnmarshalInterface(
80 pStm,
81 __uuidof( IDataObject ),
82 (void**)&pIDo );
84 hr = pStm->Release( );
87 #else
89 hr = CoGetInterfaceAndReleaseStream(
90 g_pStm,
91 __uuidof( IDataObject ),
92 (void**)&pIDo
95 #endif
97 IEnumFORMATETC* pIEEtc;
98 hr = pIDo->EnumFormatEtc( DATADIR_GET, &pIEEtc );
100 hr = OleIsCurrentClipboard( pIDo );
102 hr = OleFlushClipboard( );
104 OleUninitialize( );
106 return 0;
109 // main
111 int SAL_CALL main( int nArgc, char* Argv[] )
113 HRESULT hr = OleInitialize( NULL );
115 g_hEvtThreadWakeup = CreateEvent( 0,
116 EVT_MANUAL_RESET,
117 EVT_INIT_NONSIGNALED,
118 EVT_NONAME );
120 unsigned uThreadId;
121 HANDLE hThread;
123 // create a thread in another apartment
124 hThread = (void*)_beginthreadex( NULL, 0, ThreadProc, NULL, 0, &uThreadId );
126 IDataObject* pIDo = new CXTDataObject( );
128 hr = OleSetClipboard( pIDo );
129 hr = E_FAIL;
131 hr = OleIsCurrentClipboard( pIDo );
133 //hr = OleGetClipboard( &pIDo );
134 if ( SUCCEEDED( hr ) )
136 #ifdef RAW_MARSHALING
138 IStream* pStm = NULL;
140 hr = CreateStreamOnHGlobal( 0, FALSE, &pStm );
141 if ( SUCCEEDED( hr ) )
143 hr = CoMarshalInterface(
144 pStm,
145 __uuidof( IDataObject ),
146 pIDo,
147 MSHCTX_INPROC,
149 MSHLFLAGS_NORMAL );
150 if ( SUCCEEDED( hr ) )
151 hr = GetHGlobalFromStream( pStm, &g_hGlob );
153 hr = pStm->Release( );
156 #else
158 hr = CoMarshalInterThreadInterfaceInStream(
159 __uuidof( IDataObject ),
160 pIDo,
161 &g_pStm );
163 #endif
165 if ( SUCCEEDED( hr ) )
167 // wakeup the thread and waiting util it ends
168 SetEvent( g_hEvtThreadWakeup );
170 #ifdef WAIT_MSGLOOP
172 BOOL bContinue = TRUE;
174 while( bContinue )
176 DWORD dwResult = WaitForMultipleObjects(
178 &hThread,
179 TRUE,
180 0 );
182 if ( WAIT_OBJECT_0 == dwResult )
184 bContinue = FALSE;
186 else
188 MSG msg;
189 while( PeekMessage(
190 &msg,
191 NULL,
194 PM_REMOVE ) )
196 TranslateMessage(&msg);
197 DispatchMessage(&msg);
200 } // while
202 #endif
204 } // if
205 } // if
207 OleFlushClipboard( );
209 OleUninitialize( );
211 return 0;
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */