1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_dtrans.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir //_________________________________________________________________________________________________________________________ 33*cdf0e10cSrcweir // interface includes 34*cdf0e10cSrcweir //_________________________________________________________________________________________________________________________ 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir //_________________________________________________________________________________________________________________________ 37*cdf0e10cSrcweir // other includes 38*cdf0e10cSrcweir //_________________________________________________________________________________________________________________________ 39*cdf0e10cSrcweir #include <rtl/ustring.hxx> 40*cdf0e10cSrcweir #include <sal/types.h> 41*cdf0e10cSrcweir #include <osl/diagnose.h> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #include <stdio.h> 44*cdf0e10cSrcweir #if defined _MSC_VER 45*cdf0e10cSrcweir #pragma warning(push,1) 46*cdf0e10cSrcweir #endif 47*cdf0e10cSrcweir #include <windows.h> 48*cdf0e10cSrcweir #include <objbase.h> 49*cdf0e10cSrcweir #if defined _MSC_VER 50*cdf0e10cSrcweir #pragma warning(pop) 51*cdf0e10cSrcweir #endif 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir #include <memory> 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir #include <process.h> 56*cdf0e10cSrcweir #include "XTDo.hxx" 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir //------------------------------------------------------------- 59*cdf0e10cSrcweir // my defines 60*cdf0e10cSrcweir //------------------------------------------------------------- 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir #define WRITE_CB 63*cdf0e10cSrcweir #define EVT_MANUAL_RESET TRUE 64*cdf0e10cSrcweir #define EVT_INIT_NONSIGNALED FALSE 65*cdf0e10cSrcweir #define EVT_NONAME "" 66*cdf0e10cSrcweir #define WAIT_MSGLOOP 67*cdf0e10cSrcweir #define RAW_MARSHALING 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir //------------------------------------------------------------ 70*cdf0e10cSrcweir // namesapces 71*cdf0e10cSrcweir //------------------------------------------------------------ 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir using namespace ::rtl; 74*cdf0e10cSrcweir using namespace ::std; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir //------------------------------------------------------------ 77*cdf0e10cSrcweir // globales 78*cdf0e10cSrcweir //------------------------------------------------------------ 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir HANDLE g_hEvtThreadWakeup; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir #ifdef RAW_MARSHALING 83*cdf0e10cSrcweir HGLOBAL g_hGlob; 84*cdf0e10cSrcweir #else 85*cdf0e10cSrcweir IStream* g_pStm; 86*cdf0e10cSrcweir #endif 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir //################################################################ 89*cdf0e10cSrcweir // a thread in another apartment to test apartment transparency 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir unsigned int _stdcall ThreadProc(LPVOID pParam) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir // setup another apartment 94*cdf0e10cSrcweir HRESULT hr = OleInitialize( NULL ); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir WaitForSingleObject( g_hEvtThreadWakeup, INFINITE ); 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir IDataObject* pIDo; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir #ifdef RAW_MARSHALING 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir IStream* pStm = NULL; 103*cdf0e10cSrcweir hr = CreateStreamOnHGlobal( g_hGlob, FALSE, &pStm ); 104*cdf0e10cSrcweir if ( SUCCEEDED( hr ) ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir hr = CoUnmarshalInterface( 107*cdf0e10cSrcweir pStm, 108*cdf0e10cSrcweir __uuidof( IDataObject ), 109*cdf0e10cSrcweir (void**)&pIDo ); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir hr = pStm->Release( ); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir #else 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir hr = CoGetInterfaceAndReleaseStream( 117*cdf0e10cSrcweir g_pStm, 118*cdf0e10cSrcweir __uuidof( IDataObject ), 119*cdf0e10cSrcweir (void**)&pIDo 120*cdf0e10cSrcweir ); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir #endif 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir IEnumFORMATETC* pIEEtc; 125*cdf0e10cSrcweir hr = pIDo->EnumFormatEtc( DATADIR_GET, &pIEEtc ); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir hr = OleIsCurrentClipboard( pIDo ); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir hr = OleFlushClipboard( ); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir OleUninitialize( ); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir return 0; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir //################################################################ 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir //---------------------------------------------------------------- 139*cdf0e10cSrcweir // main 140*cdf0e10cSrcweir //---------------------------------------------------------------- 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir int SAL_CALL main( int nArgc, char* Argv[] ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir HRESULT hr = OleInitialize( NULL ); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir g_hEvtThreadWakeup = CreateEvent( 0, 147*cdf0e10cSrcweir EVT_MANUAL_RESET, 148*cdf0e10cSrcweir EVT_INIT_NONSIGNALED, 149*cdf0e10cSrcweir EVT_NONAME ); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir unsigned uThreadId; 152*cdf0e10cSrcweir HANDLE hThread; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // create a thread in another apartment 155*cdf0e10cSrcweir hThread = (void*)_beginthreadex( NULL, 0, ThreadProc, NULL, 0, &uThreadId ); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir IDataObject* pIDo = new CXTDataObject( ); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir hr = OleSetClipboard( pIDo ); 160*cdf0e10cSrcweir hr = E_FAIL; 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir hr = OleIsCurrentClipboard( pIDo ); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir //hr = OleGetClipboard( &pIDo ); 165*cdf0e10cSrcweir if ( SUCCEEDED( hr ) ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir #ifdef RAW_MARSHALING 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir IStream* pStm = NULL; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir hr = CreateStreamOnHGlobal( 0, FALSE, &pStm ); 172*cdf0e10cSrcweir if ( SUCCEEDED( hr ) ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir hr = CoMarshalInterface( 175*cdf0e10cSrcweir pStm, 176*cdf0e10cSrcweir __uuidof( IDataObject ), 177*cdf0e10cSrcweir pIDo, 178*cdf0e10cSrcweir MSHCTX_INPROC, 179*cdf0e10cSrcweir 0, 180*cdf0e10cSrcweir MSHLFLAGS_NORMAL ); 181*cdf0e10cSrcweir if ( SUCCEEDED( hr ) ) 182*cdf0e10cSrcweir hr = GetHGlobalFromStream( pStm, &g_hGlob ); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir hr = pStm->Release( ); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir #else 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir hr = CoMarshalInterThreadInterfaceInStream( 190*cdf0e10cSrcweir __uuidof( IDataObject ), 191*cdf0e10cSrcweir pIDo, 192*cdf0e10cSrcweir &g_pStm ); 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir #endif 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir if ( SUCCEEDED( hr ) ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir // wakeup the thread and waiting util it ends 199*cdf0e10cSrcweir SetEvent( g_hEvtThreadWakeup ); 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir #ifdef WAIT_MSGLOOP 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir BOOL bContinue = TRUE; 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir while( bContinue ) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir DWORD dwResult = WaitForMultipleObjects( 208*cdf0e10cSrcweir 1, 209*cdf0e10cSrcweir &hThread, 210*cdf0e10cSrcweir TRUE, 211*cdf0e10cSrcweir 0 ); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir if ( WAIT_OBJECT_0 == dwResult ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir bContinue = FALSE; 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir else 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir MSG msg; 220*cdf0e10cSrcweir while( PeekMessage( 221*cdf0e10cSrcweir &msg, 222*cdf0e10cSrcweir NULL, 223*cdf0e10cSrcweir 0, 224*cdf0e10cSrcweir 0, 225*cdf0e10cSrcweir PM_REMOVE ) ) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir TranslateMessage(&msg); 228*cdf0e10cSrcweir DispatchMessage(&msg); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir } // while 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir #endif 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir } // if 236*cdf0e10cSrcweir } // if 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir OleFlushClipboard( ); 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir OleUninitialize( ); 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir return 0; 243*cdf0e10cSrcweir } 244