Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / dtrans / source / win32 / workbench / testmarshal.cxx
blobd9edfe7531078f50e378544e2fde777c0ab7f3ba
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>
23 #include <stdio.h>
24 #if defined _MSC_VER
25 #pragma warning(push,1)
26 #endif
27 #include <windows.h>
28 #include <objbase.h>
29 #if defined _MSC_VER
30 #pragma warning(pop)
31 #endif
33 #include <memory>
35 #include <process.h>
36 #include "XTDo.hxx"
38 // my defines
40 #define WRITE_CB
41 #define EVT_MANUAL_RESET TRUE
42 #define EVT_INIT_NONSIGNALED FALSE
43 #define EVT_NONAME ""
44 #define WAIT_MSGLOOP
45 #define RAW_MARSHALING
47 // namespaces
49 using namespace ::std;
51 // globales
53 HANDLE g_hEvtThreadWakeup;
55 #ifdef RAW_MARSHALING
56 HGLOBAL g_hGlob;
57 #else
58 IStream* g_pStm;
59 #endif
61 // a thread in another apartment to test apartment transparency
63 unsigned int _stdcall ThreadProc(LPVOID pParam)
65 // setup another apartment
66 HRESULT hr = OleInitialize( NULL );
68 WaitForSingleObject( g_hEvtThreadWakeup, INFINITE );
70 IDataObject* pIDo = NULL;
72 #ifdef RAW_MARSHALING
74 IStream* pStm = NULL;
75 hr = CreateStreamOnHGlobal( g_hGlob, FALSE, &pStm );
76 if ( SUCCEEDED( hr ) )
78 hr = CoUnmarshalInterface(
79 pStm,
80 __uuidof( IDataObject ),
81 (void**)&pIDo );
83 hr = pStm->Release( );
86 #else
88 hr = CoGetInterfaceAndReleaseStream(
89 g_pStm,
90 __uuidof( IDataObject ),
91 (void**)&pIDo
94 #endif
96 IEnumFORMATETC* pIEEtc;
97 hr = pIDo->EnumFormatEtc( DATADIR_GET, &pIEEtc );
99 hr = OleIsCurrentClipboard( pIDo );
101 hr = OleFlushClipboard( );
103 OleUninitialize( );
105 return 0;
108 // main
110 int SAL_CALL main( int nArgc, char* Argv[] )
112 HRESULT hr = OleInitialize( NULL );
114 g_hEvtThreadWakeup = CreateEvent( 0,
115 EVT_MANUAL_RESET,
116 EVT_INIT_NONSIGNALED,
117 EVT_NONAME );
119 unsigned uThreadId;
120 HANDLE hThread;
122 // create a thread in another apartment
123 hThread = (void*)_beginthreadex( NULL, 0, ThreadProc, NULL, 0, &uThreadId );
125 IDataObject* pIDo = new CXTDataObject( );
127 hr = OleSetClipboard( pIDo );
128 hr = E_FAIL;
130 hr = OleIsCurrentClipboard( pIDo );
132 //hr = OleGetClipboard( &pIDo );
133 if ( SUCCEEDED( hr ) )
135 #ifdef RAW_MARSHALING
137 IStream* pStm = NULL;
139 hr = CreateStreamOnHGlobal( 0, FALSE, &pStm );
140 if ( SUCCEEDED( hr ) )
142 hr = CoMarshalInterface(
143 pStm,
144 __uuidof( IDataObject ),
145 pIDo,
146 MSHCTX_INPROC,
148 MSHLFLAGS_NORMAL );
149 if ( SUCCEEDED( hr ) )
150 hr = GetHGlobalFromStream( pStm, &g_hGlob );
152 hr = pStm->Release( );
155 #else
157 hr = CoMarshalInterThreadInterfaceInStream(
158 __uuidof( IDataObject ),
159 pIDo,
160 &g_pStm );
162 #endif
164 if ( SUCCEEDED( hr ) )
166 // wakeup the thread and waiting util it ends
167 SetEvent( g_hEvtThreadWakeup );
169 #ifdef WAIT_MSGLOOP
171 BOOL bContinue = TRUE;
173 while( bContinue )
175 DWORD dwResult = WaitForMultipleObjects(
177 &hThread,
178 TRUE,
179 0 );
181 if ( WAIT_OBJECT_0 == dwResult )
183 bContinue = FALSE;
185 else
187 MSG msg;
188 while( PeekMessage(
189 &msg,
190 NULL,
193 PM_REMOVE ) )
195 TranslateMessage(&msg);
196 DispatchMessage(&msg);
199 } // while
201 #endif
203 } // if
204 } // if
206 OleFlushClipboard( );
208 OleUninitialize( );
210 return 0;
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */