From 507e9d6ca92bdc135b838d89fa52afa54ae8695a Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 13 Dec 2009 23:07:28 +0000 Subject: [PATCH] 2009-12-14 00:04 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbwin/win_misc.c ! Fixed WIN_ANSITOWIDE() and WIN_WIDETOANSI() to return string with proper length in all cases. Peer-review me pls. --- harbour/ChangeLog | 8 +++++++- harbour/contrib/hbwin/win_misc.c | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 53e3ffd7bc..50f4d14a88 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,12 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-12-14 00:04 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbwin/win_misc.c + ! Fixed WIN_ANSITOWIDE() and WIN_WIDETOANSI() to return string with + proper length in all cases. + Peer-review me pls. + 2009-12-13 22:47 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * src/compiler/hbmain.c * src/compiler/cmdcheck.c @@ -198,7 +204,7 @@ after conversion to/from UNICODE can be different then original number of chars, i.e. multibyte characters can be replaced by single Unicode character or one Unicode - character may use few bytes representation. + character may use few bytes representation. [DONE] 2009-12-12 12:48 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbqt/hbqt_hbqmainwindow.cpp diff --git a/harbour/contrib/hbwin/win_misc.c b/harbour/contrib/hbwin/win_misc.c index 0452f6a528..8576c5645b 100644 --- a/harbour/contrib/hbwin/win_misc.c +++ b/harbour/contrib/hbwin/win_misc.c @@ -186,17 +186,25 @@ HB_FUNC( WIN_GETCOMMANDLINEPARAM ) HB_FUNC( WIN_ANSITOWIDE ) { HB_SIZE nLen = hb_parclen( 1 ); - BSTR wString = hb_mbntowc( hb_parcx( 1 ), nLen ); + LPCSTR lpSrcMB = hb_parcx( 1 ); + DWORD dwLength = MultiByteToWideChar( CP_ACP, 0, lpSrcMB, ( int ) nLen, NULL, 0 ); + LPWSTR lpDstWide = ( LPWSTR ) hb_xgrab( ( dwLength + 1 ) * sizeof( wchar_t ) ); - hb_retclen_buffer( ( char * ) wString, nLen * sizeof( wchar_t ) ); + MultiByteToWideChar( CP_ACP, 0, lpSrcMB, ( int ) nLen, lpDstWide, dwLength + 1 ); + + hb_retclen_buffer( ( char * ) lpDstWide, dwLength * sizeof( wchar_t ) ); } HB_FUNC( WIN_WIDETOANSI ) { HB_SIZE nLen = hb_parclen( 1 ); - char * cString = hb_wcntomb( ( wchar_t * ) hb_parcx( 1 ), nLen ); + LPCWSTR lpSrcWide = ( LPCWSTR ) hb_parcx( 1 ); + DWORD dwLength = WideCharToMultiByte( CP_ACP, 0, lpSrcWide, ( int ) nLen, NULL, 0, NULL, NULL ) / sizeof( wchar_t ); + LPSTR lpDstMB = ( LPSTR ) hb_xgrab( dwLength + 1 ); - hb_retclen_buffer( cString, nLen / sizeof( wchar_t ) ); + WideCharToMultiByte( CP_ACP, 0, lpSrcWide, ( int ) nLen, lpDstMB, dwLength + 1, NULL, NULL ); + + hb_retclen_buffer( lpDstMB, ( HB_SIZE ) dwLength ); } HB_FUNC( WIN_N2P )