From b21fa47ec0435cbf96b80a2d3334a904204a5abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Wed, 10 May 2017 17:21:27 +0200 Subject: [PATCH] 2017-05-10 17:21 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/hbwin/olecore.c + added functions which changes default method of NIL conversion to OLE variant: __oleVariantNil2Null( [] ) -> By default NIL values passed to foreign OLE code are converted to VT_EMPTY variants. __oleVariantNil2Null( .t. ) changes this behavior so NIL values are converted to VT_NULL variants. ; Warning: This function was added for tests. Looks that it's expected behavior for communication with MS-Excel and allows to use NIL as default parameter value but potentially it may create problems with some custom OLE interfaces so this modification should be widely tested in real life before we change the default behavior. --- ChangeLog.txt | 15 +++++++++++++++ contrib/hbwin/hbwin.hbx | 1 + contrib/hbwin/olecore.c | 32 +++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index eb4b78ae50..93213a791a 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,21 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2017-05-10 17:21 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * contrib/hbwin/olecore.c + + added functions which changes default method of NIL conversion to + OLE variant: + __oleVariantNil2Null( [] ) -> + By default NIL values passed to foreign OLE code are converted to + VT_EMPTY variants. __oleVariantNil2Null( .t. ) changes this behavior + so NIL values are converted to VT_NULL variants. + ; Warning: This function was added for tests. Looks that it's expected + behavior for communication with MS-Excel and allows to use + NIL as default parameter value but potentially it may create + problems with some custom OLE interfaces so this modification + should be widely tested in real life before we change the + default behavior. + 2017-05-10 16:39 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/hbwin/olecore.c - removed support for VT_DECIMAL and VT_PTR arrays from diff --git a/contrib/hbwin/hbwin.hbx b/contrib/hbwin/hbwin.hbx index 18b541cc2e..4b40e41295 100644 --- a/contrib/hbwin/hbwin.hbx +++ b/contrib/hbwin/hbwin.hbx @@ -432,6 +432,7 @@ DYNAMIC __oleIsDisp DYNAMIC __oleVariantGetType DYNAMIC __oleVariantGetValue DYNAMIC __oleVariantNew +DYNAMIC __oleVariantNil2Null DYNAMIC __oleVariantNullDate DYNAMIC __wapi_DEVMODE_Get DYNAMIC __wapi_DEVMODE_New diff --git a/contrib/hbwin/olecore.c b/contrib/hbwin/olecore.c index 3014112c26..018788e2ba 100644 --- a/contrib/hbwin/olecore.c +++ b/contrib/hbwin/olecore.c @@ -86,6 +86,7 @@ typedef struct { HRESULT lOleError; HB_BOOL fNullDate; + HB_BOOL fNil2Null; int iInit; } HB_OLEDATA, * PHB_OLEDATA; @@ -93,6 +94,10 @@ static void hb_oleDataInit( void * cargo ) { PHB_OLEDATA pOleData = ( PHB_OLEDATA ) cargo; + /* default settings: */ + pOleData->fNullDate = HB_FALSE; + pOleData->fNil2Null = HB_FALSE; + #if defined( HB_OS_WIN_CE ) if( CoInitializeEx( NULL, COINIT_APARTMENTTHREADED ) == S_OK ) #else @@ -148,6 +153,17 @@ static HB_BOOL hb_oleGetNullDateFlag( void ) } +static void hb_oleSetNil2NullFlag( HB_BOOL fNil2Null ) +{ + hb_getOleData()->fNil2Null = fNil2Null; +} + +static HB_BOOL hb_oleGetNil2NullFlag( void ) +{ + return hb_getOleData()->fNil2Null; +} + + static void hb_olecore_init( void * cargo ) { HB_SYMBOL_UNUSED( cargo ); @@ -799,6 +815,7 @@ static void hb_oleItemToVariantRef( VARIANT * pVariant, PHB_ITEM pItem, case HB_IT_TIMESTAMP: { double dDate = hb_itemGetTD( pItem ); + if( dDate == 0 && hb_oleGetNullDateFlag() ) { V_VT( pVariant ) = VT_NULL; @@ -896,6 +913,11 @@ static void hb_oleItemToVariantRef( VARIANT * pVariant, PHB_ITEM pItem, } break; + case HB_IT_NIL: + if( hb_oleGetNil2NullFlag() ) + V_VT( pVariant ) = VT_NULL; + /* fallthrough */ + default: if( pVarRef ) { @@ -2602,7 +2624,7 @@ HB_FUNC( __OLEVARIANTNEW ) hb_errRT_OLE( EG_ARG, 1018, 0, NULL, HB_ERR_FUNCNAME, NULL ); } -/* __oleVariantNullDate( [] ) -> */ +/* __oleVariantNullDate( [] ) -> */ HB_FUNC( __OLEVARIANTNULLDATE ) { hb_retl( hb_oleGetNullDateFlag() ); @@ -2610,6 +2632,14 @@ HB_FUNC( __OLEVARIANTNULLDATE ) hb_oleSetNullDateFlag( hb_parl( 1 ) ); } +/* __oleVariantNil2Null( [] ) -> */ +HB_FUNC( __OLEVARIANTNIL2NULL ) +{ + hb_retl( hb_oleGetNil2NullFlag() ); + if( HB_ISLOG( 1 ) ) + hb_oleSetNil2NullFlag( hb_parl( 1 ) ); +} + HB_CALL_ON_STARTUP_BEGIN( _hb_olecore_init_ ) hb_vmAtInit( hb_olecore_init, NULL ); HB_CALL_ON_STARTUP_END( _hb_olecore_init_ )