diff --git a/harbour/ChangeLog b/harbour/ChangeLog index c36c3cb299..9789874904 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,20 @@ past entries belonging to these authors: Viktor Szakats. */ +2009-05-25 18:45 UTC+0300 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) + * harbour/contrib/hbwin/hbwinole.h + * changed HB_OLE_C_API define to be compatible to other similar + defines, i.e. defined() vs. !defined() instead of 1 vs. 0 + + * harbour/contrib/hbwin/axcore.c + ! fixed missing IDispatchVtbl definition in C++ mode + + * harbour/contrib/hbwin/hbwinole.h + * harbour/contrib/hbwin/axcore.c + * harbour/contrib/hbwin/olecore.c + * a few C/C++ compatibility macros introduced. Cleaned code: two + version of method call code is not required any more + 2009-05-25 17:08 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbxvm.h * harbour/source/vm/hvm.c @@ -39,7 +53,7 @@ 2009-05-25 14:44 UTC+0300 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) * harbour/contrib/hbwin/axcore.c - ! fixed a few C++ compile warinings + ! fixed a few C++ compile errors 2009-05-25 13:22 UTC+0200 Viktor Szakats (harbour.01 syenar hu) + utils/hbformat/hbformac.c diff --git a/harbour/contrib/hbwin/axcore.c b/harbour/contrib/hbwin/axcore.c index 2f119aac6d..e64fa106d0 100644 --- a/harbour/contrib/hbwin/axcore.c +++ b/harbour/contrib/hbwin/axcore.c @@ -133,13 +133,8 @@ HB_FUNC( __AXGETCONTROL ) /* ( hWnd ) --> pDisp */ if( lOleError == S_OK ) { -#if HB_OLE_C_API - lOleError = pUnk->lpVtbl->QueryInterface( pUnk, &IID_IDispatch, ( void** ) ( void * ) &pDisp ); - pUnk->lpVtbl->Release( pUnk ); -#else - lOleError = pUnk->QueryInterface( IID_IDispatch, ( void** ) ( void * ) &pDisp ); - pUnk->Release(); -#endif + lOleError = HB_VTBL( pUnk )->QueryInterface( HB_THIS_( pUnk ) HB_ID_REF( IID_IDispatch ), ( void** ) ( void * ) &pDisp ); + HB_VTBL( pUnk )->Release( HB_THIS( pUnk ) ); } hb_oleSetError( lOleError ); @@ -151,6 +146,21 @@ HB_FUNC( __AXGETCONTROL ) /* ( hWnd ) --> pDisp */ } /* ======================== Event handler support ======================== */ + +#if !defined( HB_OLE_C_API ) +typedef struct +{ + HRESULT ( STDMETHODCALLTYPE * QueryInterface ) ( IDispatch*, REFIID, void** ); + ULONG ( STDMETHODCALLTYPE * AddRef ) ( IDispatch* ); + ULONG ( STDMETHODCALLTYPE * Release ) ( IDispatch* ); + HRESULT ( STDMETHODCALLTYPE * GetTypeInfoCount ) ( IDispatch*, UINT* ); + HRESULT ( STDMETHODCALLTYPE * GetTypeInfo ) ( IDispatch*, UINT, LCID, ITypeInfo** ); + HRESULT ( STDMETHODCALLTYPE * GetIDsOfNames ) ( IDispatch*, REFIID, LPOLESTR*, UINT, LCID, DISPID* ); + HRESULT ( STDMETHODCALLTYPE * Invoke ) ( IDispatch*, DISPID, REFIID, LCID, WORD, DISPPARAMS*, VARIANT*, EXCEPINFO*, UINT* ); +} IDispatchVtbl; +#endif + + typedef struct { IDispatchVtbl* lpVtbl; DWORD count; @@ -171,17 +181,12 @@ static HB_GARBAGE_FUNC( hb_sink_destructor ) } if( pSink->pConnectionPoint ) { -#if HB_OLE_C_API - pSink->pConnectionPoint->lpVtbl->Unadvise( pSink->pConnectionPoint, pSink->dwCookie ); - pSink->pConnectionPoint->lpVtbl->Release( pSink->pConnectionPoint ); -#else - pSink->pConnectionPoint->Unadvise( pSink->dwCookie ); - pSink->pConnectionPoint->Release(); -#endif + HB_VTBL( pSink->pConnectionPoint )->Unadvise( HB_THIS_( pSink->pConnectionPoint ) pSink->dwCookie ); + HB_VTBL( pSink->pConnectionPoint )->Release( HB_THIS( pSink->pConnectionPoint ) ); pSink->pConnectionPoint = NULL; pSink->dwCookie = 0; } - pSink->lpVtbl->Release( ( IDispatch* ) pSink ); + HB_VTBL( ( IDispatch* ) pSink )->Release( HB_THIS( ( IDispatch* ) pSink ) ); } @@ -190,7 +195,7 @@ static HRESULT STDMETHODCALLTYPE QueryInterface( IDispatch* lpThis, REFIID riid, if( IsEqualIID( riid, HB_ID_REF( IID_IUnknown ) ) || IsEqualIID( riid, HB_ID_REF( IID_IDispatch ) ) ) { *ppRet = ( void* ) lpThis; - ( ( ISink* ) lpThis)->lpVtbl->AddRef( lpThis ); + HB_VTBL( lpThis )->AddRef( HB_THIS( lpThis ) ); return S_OK; } *ppRet = NULL; @@ -313,18 +318,10 @@ HB_FUNC( __AXREGISTERHANDLER ) /* ( pDisp, bHandler ) --> pSink */ { if( pItemBlock ) { -#if HB_OLE_C_API - lOleError = pDisp->lpVtbl->QueryInterface( pDisp, &IID_IConnectionPointContainer, ( void** ) ( void* ) &pCPC ); -#else - lOleError = pDisp->QueryInterface( IID_IConnectionPointContainer, ( void** ) ( void* ) &pCPC ); -#endif + lOleError = HB_VTBL( pDisp )->QueryInterface( HB_THIS_( pDisp ) HB_ID_REF( IID_IConnectionPointContainer ), ( void** ) ( void* ) &pCPC ); if ( lOleError == S_OK ) { -#if HB_OLE_C_API - lOleError = pCPC->lpVtbl->FindConnectionPoint( pCPC, &IID_IDispatch, &pCP ); -#else - lOleError = pCPC->FindConnectionPoint( IID_IDispatch, &pCP ); -#endif + lOleError = HB_VTBL( pCPC )->FindConnectionPoint( HB_THIS_( pCPC ) HB_ID_REF( IID_IDispatch ), &pCP ); if( lOleError == S_OK ) { pSink = ( ISink* ) hb_gcAlloc( sizeof( ISink ), hb_sink_destructor ); /* TODO: GlobalAlloc GMEM_FIXED ??? */ @@ -332,21 +329,13 @@ HB_FUNC( __AXREGISTERHANDLER ) /* ( pDisp, bHandler ) --> pSink */ pSink->count = 2; /* 1 for pCP->Advice() param and 1 for Harbour collectible pointer [Mindaugas] */ pSink->pItemHandler = hb_itemNew( pItemBlock ); -#if HB_OLE_C_API - lOleError = pCP->lpVtbl->Advise( pCP, ( IUnknown* ) pSink, &dwCookie ); -#else - lOleError = pCP->Advise( ( IUnknown* ) pSink, &dwCookie ); -#endif + lOleError = HB_VTBL( pCP )->Advise( HB_THIS_( pCP ) ( IUnknown* ) pSink, &dwCookie ); pSink->pConnectionPoint = pCP; pSink->dwCookie = dwCookie; hb_retptrGC( pSink ); } -#if HB_OLE_C_API - pCPC->lpVtbl->Release( pCPC ); -#else - pCPC->Release(); -#endif + HB_VTBL( pCPC )->Release( HB_THIS( pCPC ) ); } hb_oleSetError( lOleError ); diff --git a/harbour/contrib/hbwin/hbwinole.h b/harbour/contrib/hbwin/hbwinole.h index 1e339cfdab..d8d2b45dfe 100644 --- a/harbour/contrib/hbwin/hbwinole.h +++ b/harbour/contrib/hbwin/hbwinole.h @@ -84,11 +84,16 @@ #if defined( __cplusplus ) && !defined( CINTERFACE ) && \ ( defined( __BORLANDC__ ) || defined( _MSC_VER ) || \ ( defined(__WATCOMC__) && ( __WATCOMC__ >= 1270 ) ) ) -# define HB_OLE_C_API 0 # define HB_ID_REF( id ) ( id ) +# define HB_VTBL( pSelf ) ( pSelf ) +# define HB_THIS( pSelf ) +# define HB_THIS_( pSelf ) #else # define HB_OLE_C_API 1 # define HB_ID_REF( id ) ( &id ) +# define HB_VTBL( pSelf ) ( pSelf )->lpVtbl +# define HB_THIS( pSelf ) ( pSelf ) +# define HB_THIS_( pSelf ) ( pSelf ), #endif HB_EXTERN_BEGIN diff --git a/harbour/contrib/hbwin/olecore.c b/harbour/contrib/hbwin/olecore.c index 52de43d56c..bf4cd7c260 100644 --- a/harbour/contrib/hbwin/olecore.c +++ b/harbour/contrib/hbwin/olecore.c @@ -108,11 +108,7 @@ static HB_GARBAGE_FUNC( hb_ole_destructor ) if( *ppDisp ) { -#if HB_OLE_C_API - ( *ppDisp )->lpVtbl->Release( *ppDisp ); -#else - ( *ppDisp )->Release(); -#endif + HB_VTBL( *ppDisp )->Release( HB_THIS( *ppDisp ) ); *ppDisp = NULL; } } @@ -124,11 +120,7 @@ static HB_GARBAGE_FUNC( hb_oleenum_destructor ) if( *ppEnum ) { -#if HB_OLE_C_API - ( *ppEnum )->lpVtbl->Release( *ppEnum ); -#else - ( *ppEnum )->Release(); -#endif + HB_VTBL( *ppEnum )->Release( HB_THIS( *ppEnum ) ); *ppEnum = NULL; } } @@ -251,11 +243,7 @@ void hb_oleItemToVariant( VARIANT* pVariant, PHB_ITEM pItem ) /* pVariant will be freed using VariantClear(). We increment reference count to keep OLE object alive */ -#if HB_OLE_C_API - pDisp->lpVtbl->AddRef( pDisp ); -#else - pDisp->AddRef(); -#endif + HB_VTBL( pDisp )->AddRef( HB_THIS( pDisp ) ); pVariant->n1.n2.vt = VT_DISPATCH; pVariant->n1.n2.n3.pdispVal = pDisp; } @@ -336,11 +324,7 @@ void hb_oleVariantToItem( PHB_ITEM pItem, VARIANT* pVariant ) pPtrGC = hb_itemPutPtrGC( NULL, ppDisp ); /* Item is one more copy of the object */ -#if HB_OLE_C_API - ( *ppDisp )->lpVtbl->AddRef( *ppDisp ); -#else - ( *ppDisp )->AddRef(); -#endif + HB_VTBL( *ppDisp )->AddRef( HB_THIS( *ppDisp ) ); hb_vmPushDynSym( s_pDyns_hObjAssign ); hb_vmPush( pObject ); @@ -535,8 +519,7 @@ HB_FUNC( __OLECREATEOBJECT ) /* ( cOleName | cCLSID [, cIID ] ) */ HB_FUNC( __OLEGETACTIVEOBJECT ) /* ( cOleName | cCLSID [, cIID ] ) */ { BSTR wCLSID; - IID ClassID, iid; - BOOL fIID = FALSE; + IID ClassID, iid = IID_IDispatch; IDispatch* pDisp = NULL; IDispatch** ppDisp; IUnknown* pUnk = NULL; @@ -560,12 +543,10 @@ HB_FUNC( __OLEGETACTIVEOBJECT ) /* ( cOleName | cCLSID [, cIID ] ) */ wCLSID = (BSTR) AnsiToWide( (LPSTR) cID ); lOleError = CLSIDFromString( wCLSID, &iid ); hb_xfree( wCLSID ); - fIID = TRUE; } else if( hb_parclen( 2 ) == ( ULONG ) sizeof( iid ) ) { memcpy( ( LPVOID ) &iid, cID, sizeof( iid ) ); - fIID = TRUE; } } @@ -574,11 +555,7 @@ HB_FUNC( __OLEGETACTIVEOBJECT ) /* ( cOleName | cCLSID [, cIID ] ) */ lOleError = GetActiveObject( HB_ID_REF( ClassID ), NULL, &pUnk ); if ( lOleError == S_OK ) -#if HB_OLE_C_API - lOleError = pUnk->lpVtbl->QueryInterface( pUnk, fIID ? &iid : &IID_IDispatch, ( void** ) ( void * ) &pDisp ); -#else - lOleError = pUnk->QueryInterface( fIID ? iid : IID_IDispatch, ( void** ) ( void * ) &pDisp ); -#endif + lOleError = HB_VTBL( pUnk )->QueryInterface( HB_THIS_( pUnk ) HB_ID_REF( iid ), ( void** ) ( void * ) &pDisp ); } } else @@ -617,34 +594,21 @@ HB_FUNC( __OLEENUMCREATE ) /* ( __hObj ) */ memset( &dispparam, 0, sizeof( dispparam ) ); /* empty parameters */ VariantInit( &variant ); -#if HB_OLE_C_API - lOleError = pDisp->lpVtbl->Invoke( pDisp, DISPID_NEWENUM, &IID_NULL, - LOCALE_USER_DEFAULT, - DISPATCH_PROPERTYGET, - &dispparam, &variant, &excep, &uiArgErr ); -#else - lOleError = pDisp->Invoke( DISPID_NEWENUM, IID_NULL, - LOCALE_USER_DEFAULT, - DISPATCH_PROPERTYGET, - &dispparam, &variant, &excep, &uiArgErr ); -#endif + lOleError = HB_VTBL( pDisp )->Invoke( HB_THIS_( pDisp ) DISPID_NEWENUM, HB_ID_REF( IID_NULL ), + LOCALE_USER_DEFAULT, + DISPATCH_PROPERTYGET, + &dispparam, &variant, &excep, &uiArgErr ); if( lOleError == S_OK ) { if( variant.n1.n2.vt == VT_UNKNOWN ) -#if HB_OLE_C_API - lOleError = ( variant.n1.n2.n3.punkVal )->lpVtbl->QueryInterface( variant.n1.n2.n3.punkVal, - &IID_IEnumVARIANT, ( void** ) ( void * ) &pEnum ); -#else - lOleError = ( variant.n1.n2.n3.punkVal )->QueryInterface( IID_IEnumVARIANT, ( void** ) ( void * ) &pEnum ); -#endif + lOleError = HB_VTBL( variant.n1.n2.n3.punkVal )->QueryInterface( + HB_THIS_( variant.n1.n2.n3.punkVal ) + HB_ID_REF( IID_IEnumVARIANT ), ( void** ) ( void * ) &pEnum ); else if( variant.n1.n2.vt == VT_DISPATCH ) -#if HB_OLE_C_API - lOleError = ( variant.n1.n2.n3.pdispVal )->lpVtbl->QueryInterface( variant.n1.n2.n3.pdispVal, - &IID_IEnumVARIANT, ( void** ) ( void * ) &pEnum ); -#else - lOleError = ( variant.n1.n2.n3.pdispVal )->QueryInterface( IID_IEnumVARIANT, ( void** ) ( void * ) &pEnum ); -#endif + lOleError = HB_VTBL( variant.n1.n2.n3.pdispVal )->QueryInterface( + HB_THIS_( variant.n1.n2.n3.pdispVal ) + HB_ID_REF( IID_IEnumVARIANT ), ( void** ) ( void * ) &pEnum ); else { hb_oleSetError( lOleError ); @@ -677,11 +641,7 @@ HB_FUNC( __OLEENUMNEXT ) VARIANTARG variant; VariantInit( &variant ); -#if HB_OLE_C_API - if( pEnum->lpVtbl->Next( pEnum, 1, &variant, NULL ) == S_OK ) -#else - if( pEnum->Next( 1, &variant, NULL ) == S_OK ) -#endif + if( HB_VTBL( pEnum )->Next( HB_THIS_( pEnum ) 1, &variant, NULL ) == S_OK ) { hb_oleVariantToItem( hb_stackReturnItem(), &variant ); VariantClear( &variant ); @@ -770,13 +730,8 @@ HB_FUNC( WIN_OLEAUTO___ONERROR ) if( szMethod[ 0 ] == '_' && hb_pcount() > 0 ) { pMemberArray = &szMethodWide[ 1 ]; -#if HB_OLE_C_API - lOleError = pDisp->lpVtbl->GetIDsOfNames( pDisp, &IID_NULL, &pMemberArray, - 1, LOCALE_USER_DEFAULT, &dispid ); -#else - lOleError = pDisp->GetIDsOfNames( IID_NULL, &pMemberArray, - 1, LOCALE_USER_DEFAULT, &dispid ); -#endif + lOleError = HB_VTBL( pDisp )->GetIDsOfNames( HB_THIS_( pDisp ) HB_ID_REF( IID_NULL ), &pMemberArray, + 1, LOCALE_USER_DEFAULT, &dispid ); if( lOleError == S_OK ) { @@ -787,17 +742,10 @@ HB_FUNC( WIN_OLEAUTO___ONERROR ) dispparam.rgdispidNamedArgs = &lPropPut; dispparam.cNamedArgs = 1; -#if HB_OLE_C_API - lOleError = pDisp->lpVtbl->Invoke( pDisp, dispid, &IID_NULL, - LOCALE_USER_DEFAULT, - DISPATCH_PROPERTYPUT, &dispparam, - NULL, &excep, &uiArgErr ); -#else - lOleError = pDisp->Invoke( dispid, IID_NULL, - LOCALE_USER_DEFAULT, - DISPATCH_PROPERTYPUT, &dispparam, - NULL, &excep, &uiArgErr ); -#endif + lOleError = HB_VTBL( pDisp )->Invoke( HB_THIS_( pDisp ) dispid, HB_ID_REF( IID_NULL ), + LOCALE_USER_DEFAULT, + DISPATCH_PROPERTYPUT, &dispparam, + NULL, &excep, &uiArgErr ); FreeParams( &dispparam ); hb_xfree( szMethodWide ); @@ -814,13 +762,8 @@ HB_FUNC( WIN_OLEAUTO___ONERROR ) /* Try property get and invoke */ pMemberArray = szMethodWide; -#if HB_OLE_C_API - lOleError = pDisp->lpVtbl->GetIDsOfNames( pDisp, &IID_NULL, &pMemberArray, - 1, LOCALE_USER_DEFAULT, &dispid ); -#else - lOleError = pDisp->GetIDsOfNames( IID_NULL, &pMemberArray, - 1, LOCALE_USER_DEFAULT, &dispid ); -#endif + lOleError = HB_VTBL( pDisp )->GetIDsOfNames( HB_THIS_( pDisp ) HB_ID_REF( IID_NULL ), + &pMemberArray, 1, LOCALE_USER_DEFAULT, &dispid ); hb_xfree( szMethodWide ); if( lOleError == S_OK ) @@ -829,17 +772,10 @@ HB_FUNC( WIN_OLEAUTO___ONERROR ) VariantInit( &variant ); GetParams( &dispparam ); -#if HB_OLE_C_API - lOleError = pDisp->lpVtbl->Invoke( pDisp, dispid, &IID_NULL, + lOleError = HB_VTBL( pDisp )->Invoke( HB_THIS_( pDisp ) dispid, HB_ID_REF( IID_NULL ), LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET | DISPATCH_METHOD, &dispparam, &variant, &excep, &uiArgErr ); -#else - lOleError = pDisp->Invoke( dispid, IID_NULL, - LOCALE_USER_DEFAULT, - DISPATCH_PROPERTYGET | DISPATCH_METHOD, - &dispparam, &variant, &excep, &uiArgErr ); -#endif FreeParams( &dispparam ); hb_oleVariantToItem( hb_stackReturnItem(), &variant );