From 6844b06c1fdc37bfdd92eabef42f2961d79b16ef Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Sat, 23 Jul 2011 13:08:53 +0000 Subject: [PATCH] 2011-07-23 15:08 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/hbwin/olecore.c ! fixed to use Harbour STR API instead of hardcoded ANSI CP for conversions between Harbour and OLE items. Patch provided by Phil Krylov with some minor modifications. --- harbour/ChangeLog | 6 ++++++ harbour/contrib/hbwin/olecore.c | 26 +++++++++----------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index ced7f2a4e4..a767b50f68 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,12 @@ The license applies to all entries newer than 2009-04-28. */ +2011-07-23 15:08 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/contrib/hbwin/olecore.c + ! fixed to use Harbour STR API instead of hardcoded ANSI CP for + conversions between Harbour and OLE items. + Patch provided by Phil Krylov with some minor modifications. + 2011-07-22 23:13 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/rtl/hbcom.c ! updated to compile on HP-UX - please test. diff --git a/harbour/contrib/hbwin/olecore.c b/harbour/contrib/hbwin/olecore.c index a9f9cf9ae6..9b22934e72 100644 --- a/harbour/contrib/hbwin/olecore.c +++ b/harbour/contrib/hbwin/olecore.c @@ -52,7 +52,9 @@ */ #include "hbwinole.h" +#include "hbapicdp.h" #include "hbapilng.h" +#include "hbapistr.h" #include "hbinit.h" /* enable workaround for wrong OLE variant structure definition */ @@ -337,29 +339,19 @@ static void AnsiToWideBuffer( const char* szString, wchar_t* szWide, int iLen ) static BSTR hb_oleItemToString( PHB_ITEM pItem ) { - const char* szString; - BSTR strVal; - int iLen, iStrLen; + UINT uiStrLen = ( UINT ) hb_itemCopyStrU16( pItem, HB_CDP_ENDIAN_NATIVE, + NULL, UINT_MAX ); + BSTR strVal = SysAllocStringLen( NULL, uiStrLen ); + + hb_itemCopyStrU16( pItem, HB_CDP_ENDIAN_NATIVE, strVal, uiStrLen + 1 ); - szString = hb_itemGetCPtr( pItem ); - iLen = ( int ) hb_itemGetCLen( pItem ); - iStrLen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szString, iLen, NULL, 0 ); - strVal = SysAllocStringLen( NULL, iStrLen ); - MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szString, iLen, strVal, iStrLen + 1 ); return strVal; } - static void hb_oleStringToItem( BSTR strVal, PHB_ITEM pItem ) { - char* szString; - int iLen, iStrLen; - - iStrLen = ( int ) SysStringLen( strVal ); - iLen = WideCharToMultiByte( CP_ACP, 0, strVal, iStrLen, NULL, 0, NULL, NULL ); - szString = ( char* ) hb_xgrab( ( iLen + 1 ) * sizeof( char ) ); - WideCharToMultiByte( CP_ACP, 0, strVal, iStrLen, szString, iLen + 1, NULL, NULL ); - hb_itemPutCLPtr( pItem, szString, iLen ); + hb_itemPutStrLenU16( pItem, HB_CDP_ENDIAN_NATIVE, strVal, + SysStringLen( strVal ) ); }