Files
libreoffice/dtrans/source/win32/workbench/testmarshal.cxx

247 lines
6.4 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2001-01-31 14:37:29 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2001-01-31 14:37:29 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2001-01-31 14:37:29 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2001-01-31 14:37:29 +00:00
*
* This file is part of OpenOffice.org.
2001-01-31 14:37:29 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2001-01-31 14:37:29 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2001-01-31 14:37:29 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2001-01-31 14:37:29 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dtrans.hxx"
2001-01-31 14:37:29 +00:00
//_________________________________________________________________________________________________________________________
// interface includes
//_________________________________________________________________________________________________________________________
2001-01-31 14:37:29 +00:00
//_________________________________________________________________________________________________________________________
// other includes
//_________________________________________________________________________________________________________________________
#include <rtl/ustring.hxx>
2001-01-31 14:37:29 +00:00
#include <sal/types.h>
#include <osl/diagnose.h>
#include <stdio.h>
#if defined _MSC_VER
#pragma warning(push,1)
#endif
2001-01-31 14:37:29 +00:00
#include <windows.h>
#include <objbase.h>
#if defined _MSC_VER
#pragma warning(pop)
#endif
2001-01-31 14:37:29 +00:00
#include <memory>
2001-01-31 14:37:29 +00:00
#include <process.h>
#include "XTDo.hxx"
2001-01-31 14:37:29 +00:00
//-------------------------------------------------------------
// my defines
//-------------------------------------------------------------
#define WRITE_CB
#define EVT_MANUAL_RESET TRUE
#define EVT_INIT_NONSIGNALED FALSE
#define EVT_NONAME ""
#define WAIT_MSGLOOP
#define RAW_MARSHALING
2001-01-31 14:37:29 +00:00
//------------------------------------------------------------
// namesapces
//------------------------------------------------------------
using namespace ::rtl;
using namespace ::std;
//------------------------------------------------------------
// globales
//------------------------------------------------------------
HANDLE g_hEvtThreadWakeup;
2001-01-31 14:37:29 +00:00
#ifdef RAW_MARSHALING
HGLOBAL g_hGlob;
#else
IStream* g_pStm;
#endif
2001-01-31 14:37:29 +00:00
2001-07-26 10:20:56 +00:00
//################################################################
// a thread in another apartment to test apartment transparency
unsigned int _stdcall ThreadProc(LPVOID pParam)
{
// setup another apartment
HRESULT hr = OleInitialize( NULL );
WaitForSingleObject( g_hEvtThreadWakeup, INFINITE );
2001-07-26 10:20:56 +00:00
IDataObject* pIDo;
2001-07-26 10:20:56 +00:00
#ifdef RAW_MARSHALING
IStream* pStm = NULL;
hr = CreateStreamOnHGlobal( g_hGlob, FALSE, &pStm );
if ( SUCCEEDED( hr ) )
2001-01-31 14:37:29 +00:00
{
hr = CoUnmarshalInterface(
pStm,
__uuidof( IDataObject ),
(void**)&pIDo );
2001-01-31 14:37:29 +00:00
hr = pStm->Release( );
}
2001-01-31 14:37:29 +00:00
#else
2001-01-31 14:37:29 +00:00
hr = CoGetInterfaceAndReleaseStream(
g_pStm,
__uuidof( IDataObject ),
(void**)&pIDo
);
2001-01-31 14:37:29 +00:00
#endif
2001-01-31 14:37:29 +00:00
IEnumFORMATETC* pIEEtc;
hr = pIDo->EnumFormatEtc( DATADIR_GET, &pIEEtc );
2001-01-31 14:37:29 +00:00
hr = OleIsCurrentClipboard( pIDo );
2001-01-31 14:37:29 +00:00
hr = OleFlushClipboard( );
2001-01-31 14:37:29 +00:00
OleUninitialize( );
2001-01-31 14:37:29 +00:00
return 0;
}
//################################################################
//----------------------------------------------------------------
// main
//----------------------------------------------------------------
int SAL_CALL main( int nArgc, char* Argv[] )
{
HRESULT hr = OleInitialize( NULL );
2001-01-31 14:37:29 +00:00
g_hEvtThreadWakeup = CreateEvent( 0,
EVT_MANUAL_RESET,
EVT_INIT_NONSIGNALED,
EVT_NONAME );
2001-01-31 14:37:29 +00:00
unsigned uThreadId;
HANDLE hThread;
2001-01-31 14:37:29 +00:00
// create a thread in another apartment
hThread = (void*)_beginthreadex( NULL, 0, ThreadProc, NULL, 0, &uThreadId );
2001-01-31 14:37:29 +00:00
IDataObject* pIDo = new CXTDataObject( );
2001-01-31 14:37:29 +00:00
hr = OleSetClipboard( pIDo );
hr = E_FAIL;
2001-01-31 14:37:29 +00:00
hr = OleIsCurrentClipboard( pIDo );
2001-01-31 14:37:29 +00:00
//hr = OleGetClipboard( &pIDo );
if ( SUCCEEDED( hr ) )
{
#ifdef RAW_MARSHALING
2001-01-31 14:37:29 +00:00
IStream* pStm = NULL;
2001-01-31 14:37:29 +00:00
hr = CreateStreamOnHGlobal( 0, FALSE, &pStm );
if ( SUCCEEDED( hr ) )
{
hr = CoMarshalInterface(
pStm,
__uuidof( IDataObject ),
pIDo,
MSHCTX_INPROC,
0,
MSHLFLAGS_NORMAL );
if ( SUCCEEDED( hr ) )
hr = GetHGlobalFromStream( pStm, &g_hGlob );
2001-01-31 14:37:29 +00:00
hr = pStm->Release( );
}
2001-01-31 14:37:29 +00:00
#else
2001-01-31 14:37:29 +00:00
hr = CoMarshalInterThreadInterfaceInStream(
__uuidof( IDataObject ),
pIDo,
&g_pStm );
2001-01-31 14:37:29 +00:00
#endif
2001-01-31 14:37:29 +00:00
if ( SUCCEEDED( hr ) )
2001-01-31 14:37:29 +00:00
{
// wakeup the thread and waiting util it ends
SetEvent( g_hEvtThreadWakeup );
2001-01-31 14:37:29 +00:00
#ifdef WAIT_MSGLOOP
2001-01-31 14:37:29 +00:00
BOOL bContinue = TRUE;
2001-01-31 14:37:29 +00:00
while( bContinue )
2001-07-26 10:20:56 +00:00
{
DWORD dwResult = WaitForMultipleObjects(
1,
&hThread,
TRUE,
0 );
if ( WAIT_OBJECT_0 == dwResult )
{
bContinue = FALSE;
}
else
{
MSG msg;
while( PeekMessage(
&msg,
NULL,
0,
0,
PM_REMOVE ) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
} // while
#endif
} // if
} // if
2001-01-31 14:37:29 +00:00
OleFlushClipboard( );
2001-01-31 14:37:29 +00:00
OleUninitialize( );
2001-01-31 14:37:29 +00:00
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */