1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: native_share.h,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #using "cli_uretypes.dll"
35 #include "rtl/ustring.hxx"
36 #include "uno/mapping.hxx"
40 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
48 //------------------------------------------------------------------------------
49 inline ::System::String
* ustring_to_String( ::rtl::OUString
const & ustr
)
51 return new ::System::String( ustr
.getStr(), 0, ustr
.getLength() );
53 //------------------------------------------------------------------------------
54 inline ::rtl::OUString
String_to_ustring( ::System::String
* str
)
56 OSL_ASSERT( sizeof (wchar_t) == sizeof (sal_Unicode
) );
57 wchar_t const __pin
* chars
= PtrToStringChars( str
);
58 return ::rtl::OUString( chars
, str
->get_Length() );
61 template< typename T
>
62 inline ::System::Object
* to_cli(
63 ::com::sun::star::uno::Reference
< T
> const & x
)
65 ::com::sun::star::uno::Mapping
mapping(
66 OUSTR(CPPU_CURRENT_LANGUAGE_BINDING_NAME
), OUSTR(UNO_LB_CLI
) );
67 OSL_ASSERT( mapping
.is() );
70 throw ::com::sun::star::uno::RuntimeException(
71 OUSTR("cannot get mapping from C++ to CLI!"),
72 ::com::sun::star::uno::Reference
<
73 ::com::sun::star::uno::XInterface
>() );
77 reinterpret_cast< intptr_t >(
78 mapping
.mapInterface( x
.get(), ::getCppuType( &x
) ) );
79 ::System::Runtime::InteropServices::GCHandle
handle(
80 ::System::Runtime::InteropServices::GCHandle::op_Explicit( intptr
) );
81 ::System::Object
* ret
= handle
.get_Target();
86 template< typename T
>
88 ::com::sun::star::uno::Reference
< T
> * pRet
, ::System::Object
* x
)
90 ::com::sun::star::uno::Mapping
mapping(
91 OUSTR(UNO_LB_CLI
), OUSTR(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) );
92 OSL_ASSERT( mapping
.is() );
95 throw ::com::sun::star::uno::RuntimeException(
96 OUSTR("cannot get mapping from CLI to C++!"),
97 ::com::sun::star::uno::Reference
<
98 ::com::sun::star::uno::XInterface
>() );
101 ::System::Runtime::InteropServices::GCHandle
handle(
102 ::System::Runtime::InteropServices::GCHandle::Alloc( x
) );
104 mapping
.mapInterface(
105 reinterpret_cast< void ** >( &ret
),
106 reinterpret_cast< void * >(
107 ::System::Runtime::InteropServices::GCHandle::op_Explicit( handle
)
113 #error ERROR: either _WIN64 or _WIN32 must be defined
114 ERROR
: either _WIN64
or _WIN32 must be defined
117 ::getCppuType( pRet
) );
119 pRet
->set( ret
, SAL_NO_ACQUIRE
/* takeover ownership */ );