1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
25 #pragma warning(push,1)
41 #define EVT_MANUAL_RESET TRUE
42 #define EVT_INIT_NONSIGNALED FALSE
45 #define RAW_MARSHALING
49 using namespace ::std
;
53 HANDLE g_hEvtThreadWakeup
;
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
;
75 hr
= CreateStreamOnHGlobal( g_hGlob
, FALSE
, &pStm
);
76 if ( SUCCEEDED( hr
) )
78 hr
= CoUnmarshalInterface(
80 __uuidof( IDataObject
),
83 hr
= pStm
->Release( );
88 hr
= CoGetInterfaceAndReleaseStream(
90 __uuidof( IDataObject
),
96 IEnumFORMATETC
* pIEEtc
;
97 hr
= pIDo
->EnumFormatEtc( DATADIR_GET
, &pIEEtc
);
99 hr
= OleIsCurrentClipboard( pIDo
);
101 hr
= OleFlushClipboard( );
110 int SAL_CALL
main( int nArgc
, char* Argv
[] )
112 HRESULT hr
= OleInitialize( NULL
);
114 g_hEvtThreadWakeup
= CreateEvent( 0,
116 EVT_INIT_NONSIGNALED
,
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
);
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(
144 __uuidof( IDataObject
),
149 if ( SUCCEEDED( hr
) )
150 hr
= GetHGlobalFromStream( pStm
, &g_hGlob
);
152 hr
= pStm
->Release( );
157 hr
= CoMarshalInterThreadInterfaceInStream(
158 __uuidof( IDataObject
),
164 if ( SUCCEEDED( hr
) )
166 // wakeup the thread and waiting util it ends
167 SetEvent( g_hEvtThreadWakeup
);
171 BOOL bContinue
= TRUE
;
175 DWORD dwResult
= WaitForMultipleObjects(
181 if ( WAIT_OBJECT_0
== dwResult
)
195 TranslateMessage(&msg
);
196 DispatchMessage(&msg
);
206 OleFlushClipboard( );
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */