From c80c0feb2a59d9ed591f87a3bd0fa31467109672 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 26 Sep 2011 08:57:26 +0000 Subject: [PATCH] 2011-09-26 10:57 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbgtcore.h * harbour/src/rtl/gtclip.c ! fixed possible random data settings by hb_gt_winapi_setClipboard() ! fixed possible memory leak in hb_gt_winapi_setClipboard() + added new C function for WIN32 builds: HB_BOOL hb_gt_winapi_setClipboardRaw( HB_UINT uFormat, void * pData, HB_SIZE nSize ); --- harbour/ChangeLog | 9 +++++++ harbour/include/hbgtcore.h | 1 + harbour/src/rtl/gtclip.c | 48 ++++++++++++++++++++++++++++++++++---- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 394305b8b7..29462cbaf1 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,15 @@ The license applies to all entries newer than 2009-04-28. */ +2011-09-26 10:57 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbgtcore.h + * harbour/src/rtl/gtclip.c + ! fixed possible random data settings by hb_gt_winapi_setClipboard() + ! fixed possible memory leak in hb_gt_winapi_setClipboard() + + added new C function for WIN32 builds: + HB_BOOL hb_gt_winapi_setClipboardRaw( HB_UINT uFormat, + void * pData, HB_SIZE nSize ); + 2011-09-24 11:49 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbmzip/mzip.c ! HB_UNZIPFILEINFO(): date returned was off by one month. diff --git a/harbour/include/hbgtcore.h b/harbour/include/hbgtcore.h index b9870e06f7..ffc703d4fd 100644 --- a/harbour/include/hbgtcore.h +++ b/harbour/include/hbgtcore.h @@ -602,6 +602,7 @@ extern HB_BOOL hb_gt_setClipboard( const char * szClipData, HB_SIZE nLen ); extern HB_BOOL hb_gt_getClipboard( char ** pszClipData, HB_SIZE * pnLen ); #if defined( HB_OS_WIN ) extern HB_EXPORT HB_BOOL hb_gt_winapi_setClipboard( HB_UINT uFormat, PHB_ITEM pItem ); +extern HB_EXPORT HB_BOOL hb_gt_winapi_setClipboardRaw( HB_UINT uFormat, void * pData, HB_SIZE nSize ); extern HB_EXPORT HB_BOOL hb_gt_winapi_getClipboard( HB_UINT uFormat, PHB_ITEM pItem ); extern HB_EXPORT int hb_gt_winapi_getKbdState( void ); extern HB_EXPORT void hb_gt_winapi_setKbdState( int kbdShifts ); diff --git a/harbour/src/rtl/gtclip.c b/harbour/src/rtl/gtclip.c index 47592bd451..696b56d89d 100644 --- a/harbour/src/rtl/gtclip.c +++ b/harbour/src/rtl/gtclip.c @@ -118,6 +118,42 @@ HB_BOOL hb_gt_getClipboard( char ** pszClipData, HB_SIZE * pnLen ) #if defined( HB_OS_WIN ) +HB_BOOL hb_gt_winapi_setClipboardRaw( HB_UINT uFormat, void * pData, HB_SIZE nSize ) +{ + HB_BOOL fResult = HB_FALSE; + + if( OpenClipboard( NULL ) ) + { + EmptyClipboard(); + + if( nSize ) + { + /* Allocate a global memory object for the text. */ + HGLOBAL hglb = GlobalAlloc( GMEM_MOVEABLE, nSize ); + if( hglb ) + { + /* Lock the handle and copy the text to the buffer. */ + LPVOID lpMem = GlobalLock( hglb ); + + if( lpMem ) + { + memcpy( lpMem, pData, nSize ); + ( void ) GlobalUnlock( hglb ); + /* Place the handle on the clipboard. */ + fResult = SetClipboardData( ( UINT ) uFormat, hglb ) != 0; + } + if( !fResult ) + GlobalFree( hglb ); + } + } + else + fResult = HB_TRUE; + + CloseClipboard(); + } + return fResult; +} + HB_BOOL hb_gt_winapi_setClipboard( HB_UINT uFormat, PHB_ITEM pItem ) { HB_BOOL fResult = HB_FALSE; @@ -152,13 +188,17 @@ HB_BOOL hb_gt_winapi_setClipboard( HB_UINT uFormat, PHB_ITEM pItem ) else hb_itemCopyStr( pItem, hb_setGetOSCP(), ( char * ) lpMem, nSize + 1 ); - fResult = HB_TRUE; + ( void ) GlobalUnlock( hglb ); + /* Place the handle on the clipboard. */ + fResult = SetClipboardData( ( UINT ) uFormat, hglb ) != 0; } - ( void ) GlobalUnlock( hglb ); - /* Place the handle on the clipboard. */ - SetClipboardData( ( UINT ) uFormat, hglb ); + if( !fResult ) + GlobalFree( hglb ); } } + else + fResult = HB_TRUE; + CloseClipboard(); } return fResult;