rathinagiri wrote:
Hi Grigory,
I tried to compile with 3.1 and had the following problems:
1. Will "WIN_OLEAUTO" just replace TOleAuto()?
2. I got errors of not finding the libraries for functions isnil, ischar, isarray
Any ideas?
Hi Rathi,
I've prepared a working class
TOleAuto (based upon WIN_OLEAUTO) below.
Please take a look for source of file
hbole.prg :
Code: Select all
/*
* Harbour Project source code:
* Compatibility calls.
*
* Copyright 2009 Viktor Szakats (harbour.01 syenar.hu)
* www - http://harbour-project.org
*
*/
#define HB_CLS_NOTOBJECT /* avoid definition of method: INIT */
#include "hbclass.ch"
#include "common.ch"
#include "error.ch"
#define EG_OLEEXCEPTION 1001
STATIC s_bBreak := { | oError | Break( oError ) }
STATIC PROCEDURE Throw( oError )
LOCAL lError := Eval( ErrorBlock(), oError )
IF ! ISLOGICAL( lError ) .OR. lError
__ErrInHandler()
ENDIF
Break( oError )
STATIC FUNCTION ThrowOpError( nSubCode, cOperator, ... )
LOCAL oError
oError := ErrorNew()
oError:Args := { ... }
oError:CanDefault := .F.
oError:CanRetry := .F.
oError:CanSubstitute := .T.
oError:Description := "argument error"
oError:GenCode := EG_ARG
oError:Operation := cOperator
oError:Severity := ES_ERROR
oError:SubCode := nSubCode
oError:SubSystem := "BASE"
RETURN Throw( oError )
CREATE CLASS TOLEAUTO FROM WIN_OLEAUTO
/* TODO: Implement compatibility to the required extent */
VAR cClassName
METHOD New( xOle, cClass )
METHOD hObj( xOle )
METHOD OleValuePlus( xArg ) OPERATOR "+"
METHOD OleValueMinus( xArg ) OPERATOR "-"
METHOD OleValueMultiply( xArg ) OPERATOR "*"
METHOD OleValueDivide( xArg ) OPERATOR "/"
METHOD OleValueModulus( xArg ) OPERATOR "%"
METHOD OleValuePower( xArg ) OPERATOR "^"
METHOD OleValueInc() OPERATOR "++"
METHOD OleValueDec() OPERATOR "--"
METHOD OleValueEqual( xArg ) OPERATOR "="
METHOD OleValueExactEqual( xArg ) OPERATOR "=="
METHOD OleValueNotEqual( xArg ) OPERATOR "!="
ENDCLASS
METHOD hObj( xOle ) CLASS TOLEAUTO
IF PCount() > 0 .AND. xOle != NIL
IF ISNUMBER( xOle )
xOle := __OLEPDISP( xOle )
ENDIF
IF hb_isPointer( xOle )
::__hObj := xOle
ENDIF
ENDIF
RETURN ::__hObj
METHOD New( xOle, cClass ) CLASS TOLEAUTO
LOCAL hOle
LOCAL oError
IF ISNUMBER( xOle )
xOle := __OLEPDISP( xOle )
ENDIF
IF hb_isPointer( xOle )
::__hObj := xOle
IF ISCHARACTER( cClass )
::cClassName := cClass
ELSE
::cClassName := hb_ntos( win_P2N( xOle ) )
ENDIF
ELSEIF ISCHARACTER( xOle )
hOle := __OleCreateObject( xOle )
IF ! Empty( hOle )
::__hObj := hOle
::cClassName := xOle
ELSE
oError := ErrorNew()
oError:Args := hb_AParams()
oError:CanDefault := .F.
oError:CanRetry := .F.
oError:CanSubstitute := .T.
oError:Description := win_OleErrorText()
oError:GenCode := EG_OLEEXCEPTION
oError:Operation := ProcName()
oError:Severity := ES_ERROR
oError:SubCode := -1
oError:SubSystem := "TOleAuto"
RETURN Throw( oError )
ENDIF
ENDIF
RETURN Self
FUNCTION CreateObject( xOle, cClass )
RETURN TOleAuto():New( xOle, cClass )
FUNCTION GetActiveObject( xOle, cClass )
LOCAL o := TOleAuto():New()
LOCAL hOle
LOCAL oError
IF ISNUMBER( xOle )
xOle := __OLEPDISP( xOle )
ENDIF
IF hb_isPointer( xOle )
o:__hObj := xOle
IF ISCHARACTER( cClass )
o:cClassName := cClass
ELSE
o:cClassName := hb_ntos( win_P2N( xOle ) )
ENDIF
ELSEIF ISCHARACTER( xOle )
hOle := __OleGetActiveObject( xOle )
IF ! Empty( hOle )
o:__hObj := hOle
o:cClassName := xOle
ELSE
oError := ErrorNew()
oError:Args := hb_AParams()
oError:CanDefault := .F.
oError:CanRetry := .F.
oError:CanSubstitute := .T.
oError:Description := win_OleErrorText()
oError:GenCode := EG_OLEEXCEPTION
oError:Operation := ProcName()
oError:Severity := ES_ERROR
oError:SubCode := -1
oError:SubSystem := "TOleAuto"
RETURN Throw( oError )
ENDIF
ENDIF
RETURN o
METHOD OleValuePlus( xArg ) CLASS TOLEAUTO
LOCAL xRet
BEGIN SEQUENCE WITH s_bBreak
xRet := ::OleValue + xArg
RECOVER
RETURN ThrowOpError( 1081, "+", Self, xArg )
END SEQUENCE
RETURN xRet
METHOD OleValueMinus( xArg ) CLASS TOLEAUTO
LOCAL xRet
BEGIN SEQUENCE WITH s_bBreak
xRet := ::OleValue - xArg
RECOVER
RETURN ThrowOpError( 1082, "-", Self, xArg )
END SEQUENCE
RETURN xRet
METHOD OleValueMultiply( xArg ) CLASS TOLEAUTO
LOCAL xRet
BEGIN SEQUENCE WITH s_bBreak
xRet := ::OleValue * xArg
RECOVER
RETURN ThrowOpError( 1083, "*", Self, xArg )
END SEQUENCE
RETURN xRet
METHOD OleValueDivide( xArg ) CLASS TOLEAUTO
LOCAL xRet
BEGIN SEQUENCE WITH s_bBreak
xRet := ::OleValue / xArg
RECOVER
RETURN ThrowOpError( 1084, "/", Self, xArg )
END SEQUENCE
RETURN xRet
METHOD OleValueModulus( xArg ) CLASS TOLEAUTO
LOCAL xRet
BEGIN SEQUENCE WITH s_bBreak
xRet := ::OleValue % xArg
RECOVER
RETURN ThrowOpError( 1085, "%", Self, xArg )
END SEQUENCE
RETURN xRet
METHOD OleValuePower( xArg ) CLASS TOLEAUTO
LOCAL xRet
BEGIN SEQUENCE WITH s_bBreak
xRet := ::OleValue ^ xArg
RECOVER
RETURN ThrowOpError( 1088, "^", Self, xArg )
END SEQUENCE
RETURN xRet
METHOD OleValueInc() CLASS TOLEAUTO
BEGIN SEQUENCE WITH s_bBreak
++::OleValue
RECOVER
RETURN ThrowOpError( 1086, "++", Self )
END SEQUENCE
RETURN Self
METHOD OleValueDec() CLASS TOLEAUTO
BEGIN SEQUENCE WITH s_bBreak
--::OleValue
RECOVER
RETURN ThrowOpError( 1087, "--", Self )
END SEQUENCE
RETURN Self
METHOD OleValueEqual( xArg ) CLASS TOLEAUTO
LOCAL xRet
BEGIN SEQUENCE WITH s_bBreak
xRet := ( ::OleValue = xArg ) /* NOTE: Intentionally using '=' operator. */
RECOVER
RETURN ThrowOpError( 1089, "=", Self, xArg )
END SEQUENCE
RETURN xRet
METHOD OleValueExactEqual( xArg ) CLASS TOLEAUTO
LOCAL xRet
BEGIN SEQUENCE WITH s_bBreak
xRet := ( ::OleValue == xArg )
RECOVER
RETURN ThrowOpError( 1090, "==", Self, xArg )
END SEQUENCE
RETURN xRet
METHOD OleValueNotEqual( xArg ) CLASS TOLEAUTO
LOCAL xRet
BEGIN SEQUENCE WITH s_bBreak
xRet := ( ::OleValue != xArg )
RECOVER
RETURN ThrowOpError( 1091, "!=", Self, xArg )
END SEQUENCE
RETURN xRet
#pragma BEGINDUMP
#include "hbapi.h"
#include "hbwinole.h"
HB_FUNC( OLE2TXTERROR )
{
HRESULT lOleError;
if( HB_ISNUM( 1 ) )
lOleError = hb_parnl( 1 );
else
lOleError = hb_oleGetError();
switch( lOleError )
{
case S_OK: hb_retc_const( "S_OK" ); break;
case CO_E_CLASSSTRING: hb_retc_const( "CO_E_CLASSSTRING" ); break;
case OLE_E_WRONGCOMPOBJ: hb_retc_const( "OLE_E_WRONGCOMPOBJ" ); break;
case REGDB_E_CLASSNOTREG: hb_retc_const( "REGDB_E_CLASSNOTREG" ); break;
case REGDB_E_WRITEREGDB: hb_retc_const( "REGDB_E_WRITEREGDB" ); break;
case E_OUTOFMEMORY: hb_retc_const( "E_OUTOFMEMORY" ); break;
case E_INVALIDARG: hb_retc_const( "E_INVALIDARG" ); break;
case E_UNEXPECTED: hb_retc_const( "E_UNEXPECTED" ); break;
case E_NOTIMPL: hb_retc_const( "E_NOTIMPL" ); break;
case DISP_E_UNKNOWNNAME: hb_retc_const( "DISP_E_UNKNOWNNAME" ); break;
case DISP_E_UNKNOWNLCID: hb_retc_const( "DISP_E_UNKNOWNLCID" ); break;
case DISP_E_BADPARAMCOUNT: hb_retc_const( "DISP_E_BADPARAMCOUNT" ); break;
case DISP_E_BADVARTYPE: hb_retc_const( "DISP_E_BADVARTYPE" ); break;
case DISP_E_EXCEPTION: hb_retc_const( "DISP_E_EXCEPTION" ); break;
case DISP_E_MEMBERNOTFOUND: hb_retc_const( "DISP_E_MEMBERNOTFOUND" ); break;
case DISP_E_NONAMEDARGS: hb_retc_const( "DISP_E_NONAMEDARGS" ); break;
case DISP_E_OVERFLOW: hb_retc_const( "DISP_E_OVERFLOW" ); break;
case DISP_E_PARAMNOTFOUND: hb_retc_const( "DISP_E_PARAMNOTFOUND" ); break;
case DISP_E_TYPEMISMATCH: hb_retc_const( "DISP_E_TYPEMISMATCH" ); break;
case DISP_E_UNKNOWNINTERFACE: hb_retc_const( "DISP_E_UNKNOWNINTERFACE" ); break;
case DISP_E_PARAMNOTOPTIONAL: hb_retc_const( "DISP_E_PARAMNOTOPTIONAL" ); break;
default:
{
char buf[ 16 ];
hb_snprintf( buf, 16, "0x%08x", ( UINT ) ( HB_PTRUINT ) lOleError );
hb_retc( buf );
}
}
}
HB_FUNC( __OLEPDISP )
{
hb_oleInit();
hb_oleItemPut( hb_param( -1, HB_IT_ANY ),
( IDispatch * ) ( HB_PTRUINT ) hb_parnint( 1 ) );
}
#pragma ENDDUMP
and source of header file
hbwinole.h :
Code: Select all
/*
* $Id: hbwinole.h 16046 2011-01-14 07:35:19Z druzus $
*/
/*
* Harbour Project source code:
* OLE library C header
*
* Copyright 2009 Viktor Szakats (harbour.01 syenar.hu)
* www - http://harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
#ifndef __HBWINOLE_H
#define __HBWINOLE_H
#include "hbapi.h"
#include "hbapiitm.h"
#include "hbapicls.h"
#include "hbapierr.h"
#include "hbvm.h"
#include "hbstack.h"
#include "hbdate.h"
#if defined( HB_OS_WIN )
/* This option can resolve compilation problems in C++ mode for some
* compilers like OpenWatcom but not for all, f.e. it will not help
* BCC when used with -P (C++ mode) switch.
*/
/*
#if defined( __cplusplus ) && !defined( CINTERFACE )
#define CINTERFACE 1
#endif
*/
/* This code uses named union so this declaration is necessary for
* compilers where nameless unions are default
*/
#if defined( __BORLANDC__ ) || \
( defined( __WATCOMC__ ) && !defined( __cplusplus ) )
# if !defined( NONAMELESSUNION )
# define NONAMELESSUNION
# endif
#endif
#include <windows.h>
#include <ole2.h>
#include <ocidl.h>
/* MinGW is lacking a number of variant accessors
*/
#if defined( __MINGW32__ )
# if !defined( V_I1REF )
# define V_I1REF( x ) V_UNION( x, pcVal )
# endif
# if !defined( V_UI2REF )
# define V_UI2REF( x ) V_UNION( x, puiVal )
# endif
# if !defined( V_INT )
# define V_INT( x ) V_UNION( x, intVal )
# endif
# if !defined( V_INTREF )
# define V_INTREF( x ) V_UNION( x, pintVal )
# endif
# if !defined( V_UINT )
# define V_UINT( x ) V_UNION( x, uintVal )
# endif
# if !defined( V_UINTREF )
# define V_UINTREF( x ) V_UNION( x, puintVal )
# endif
#endif
#if defined( NONAMELESSUNION )
# define HB_WIN_U1( x, y ) ( x )->n1.y
# define HB_WIN_U2( x, y ) ( x )->n1.n2.y
# define HB_WIN_U3( x, y ) ( x )->n1.n2.n3.y
#else
# define HB_WIN_U1( x, y ) ( x )->y
# define HB_WIN_U2( x, y ) ( x )->y
# define HB_WIN_U3( x, y ) ( x )->y
#endif
/* macros used to hide type of interface: C or C++
*/
#if defined( __cplusplus ) && !defined( CINTERFACE ) && \
( defined( __BORLANDC__ ) || \
defined( __DMC__ ) || \
defined( _MSC_VER ) || \
defined( __MINGW32__ ) || \
( defined( __WATCOMC__ ) && ( __WATCOMC__ >= 1270 ) ) )
# 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
typedef HB_BOOL ( * HB_OLEOBJ_FUNC )( VARIANT*, PHB_ITEM );
typedef void ( * HB_OLE_DESTRUCTOR_FUNC )( void * );
extern HB_EXPORT HB_BOOL hb_oleInit( void );
extern HB_EXPORT HRESULT hb_oleGetError( void );
extern HB_EXPORT void hb_oleSetError( HRESULT lOleError );
extern HB_EXPORT void hb_oleDispatchToItem( PHB_ITEM pItem, IDispatch* pdispVal, HB_USHORT uiClass );
extern HB_EXPORT IDispatch* hb_oleItemGetDispatch( PHB_ITEM pItem );
extern HB_EXPORT void hb_oleVariantToItem( PHB_ITEM pItem, VARIANT * pVariant );
extern HB_EXPORT void hb_oleVariantToItemEx( PHB_ITEM pItem, VARIANT* pVariant, HB_USHORT uiClass );
extern HB_EXPORT void hb_oleItemToVariant( VARIANT * pVariant, PHB_ITEM pItem );
extern HB_EXPORT void hb_oleItemToVariantEx( VARIANT* pVariant, PHB_ITEM pItem, HB_OLEOBJ_FUNC pObjFunc );
extern HB_EXPORT void hb_oleVariantUpdate( VARIANT * pVariant, PHB_ITEM pItem, HB_OLEOBJ_FUNC pObjFunc );
extern HB_EXPORT IDispatch* hb_oleParam( int iParam );
extern HB_EXPORT IDispatch* hb_oleItemGet( PHB_ITEM pItem );
extern HB_EXPORT PHB_ITEM hb_oleItemPut( PHB_ITEM pItem, IDispatch * pDisp );
extern HB_EXPORT PHB_ITEM hb_oleItemGetCallBack( PHB_ITEM pItem );
extern HB_EXPORT void hb_oleItemSetCallBack( PHB_ITEM pItem, PHB_ITEM * pCallBack );
extern HB_EXPORT HB_BOOL hb_oleDispInvoke( PHB_SYMB pSym, PHB_ITEM pObject, PHB_ITEM pParam,
DISPPARAMS * pParams, VARIANT* pVarResult,
HB_OLEOBJ_FUNC pObjFunc, HB_USHORT uiClass );
extern HB_EXPORT void hb_oleItemSetDestructor( PHB_ITEM pItem, HB_OLE_DESTRUCTOR_FUNC pFunc, void * cargo );
/* activex control */
extern HB_EXPORT HB_BOOL hb_oleAxInit( void );
extern HB_EXPORT PHB_ITEM hb_oleAxControlNew( PHB_ITEM pItem, HWND hWnd );
HB_EXTERN_END
#endif
#endif /* __HBWINOLE_H */
2. You should start the following replacing to make build old C-code with Harbour 3.1.0dev
- IS*() -> HB_IS*()
Hope that helps
