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 #ifndef INCLUDED_DTRANS_SOURCE_WIN32_DTOBJ_DTRANSHELPER_HXX
21 #define INCLUDED_DTRANS_SOURCE_WIN32_DTOBJ_DTRANSHELPER_HXX
24 #pragma warning(push,1)
30 #include "../misc/WinClip.hxx"
32 #define AUTO_INIT TRUE
34 // a helper class to manage a global memory area, the clients can write
35 // into the global memory area and extract the handle to the global mem
36 // note: not thread-safe
38 class CStgTransferHelper
41 // will be thrown in case of failures
42 class CStgTransferException
46 CStgTransferException( HRESULT hr
) : m_hr( hr
) {};
51 sal_Bool bAutoInit
= sal_False
,
53 sal_Bool bDelStgOnRelease
= sal_False
);
55 ~CStgTransferHelper( );
57 void SAL_CALL
write( const void* lpData
, ULONG cb
, ULONG
* cbWritten
= NULL
);
58 void SAL_CALL
read( LPVOID pv
, ULONG cb
, ULONG
* pcbRead
= NULL
);
60 HGLOBAL SAL_CALL
getHGlobal( ) const;
61 void SAL_CALL
getIStream( LPSTREAM
* ppStream
);
65 sal_uInt32 uiFlags
= GHND
,
66 sal_Bool bDelStgOnRelease
= sal_False
);
70 sal_Bool bDelStgOnRelease
= sal_False
);
72 // returns the size of the managed memory
73 sal_uInt32 SAL_CALL
memSize( CLIPFORMAT cf
= CF_INVALID
) const;
75 // free the global memory and necessary
76 // release the internal stream pointer
77 void SAL_CALL
cleanup( );
81 sal_Bool m_bDelStgOnRelease
;
84 CStgTransferHelper( const CStgTransferHelper
& );
85 CStgTransferHelper
& operator=( const CStgTransferHelper
& );
88 // something like an auto-pointer - allows access to the memory belonging
89 // to a HGLOBAL and automatically unlocks a global memory at destruction
98 CRawHGlobalPtr( HGLOBAL hGlob
) :
100 m_bIsLocked( FALSE
),
107 CRawHGlobalPtr( const CStgTransferHelper
& theHGlobalHelper
) :
108 m_hGlob( theHGlobalHelper
.getHGlobal( ) ),
109 m_bIsLocked( FALSE
),
119 GlobalUnlock( m_hGlob
);
122 // lock the global memory (initializes a
123 // pointer to this memory)
127 if ( !m_bIsLocked
&& ( NULL
!= m_hGlob
) )
129 m_pGlobMem
= GlobalLock( m_hGlob
);
130 m_bIsLocked
= ( NULL
!= m_pGlobMem
);
136 // unlock the global memory (invalidates the
137 // pointer to this memory)
141 GlobalUnlock( m_hGlob
);
145 return ( NO_ERROR
== GetLastError( ) );
148 // locks the global memory and returns a
149 // pointer to this memory
157 // size of mem we point to
161 return GlobalSize( m_hGlob
);
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */