diff --git a/harbour/contrib/ole2/w32ole.c b/harbour/contrib/ole2/w32ole.c index 29374cffaf..ba612780be 100644 --- a/harbour/contrib/ole2/w32ole.c +++ b/harbour/contrib/ole2/w32ole.c @@ -108,6 +108,8 @@ static DISPPARAMS s_EmptyDispParams; static VARIANTARG RetVal, OleVal; +static BOOL bInit = FALSE; + // ----------------------------------------------------------------------- #define EG_OLEEXECPTION 1001 @@ -151,11 +153,37 @@ PHB_ITEM HB_EXPORT hb_itemPutCRawStatic( PHB_ITEM pItem, const char * szText, UL return pItem; } -static void TraceLog( char * cFile, ... ) +static void TraceLog( const char * sFile, const char * sTraceMsg, ... ) { - HB_SYMBOL_UNUSED( cFile ); + FILE *hFile; + + if( !sTraceMsg ) + { + return; + } + + if( sFile == NULL ) + { + hFile = fopen( "trace.log", "a" ); + } + else + { + hFile = fopen( sFile, "a" ); + } + + if( hFile ) + { + va_list ap; + + va_start( ap, sTraceMsg ); + vfprintf( hFile, sTraceMsg, ap ); + va_end( ap ); + + fclose( hFile ); + } } + // ----------------------------------------------------------------------- static EXCEPINFO excep; @@ -211,6 +239,7 @@ static void TraceLog( char * cFile, ... ) } //---------------------------------------------------------------------------// + HB_FUNC( __HB_OLE_INIT ) { if( s_pSym_TOleAuto == NULL ) @@ -230,12 +259,26 @@ static void TraceLog( char * cFile, ... ) s_EmptyDispParams.rgdispidNamedArgs = 0; s_EmptyDispParams.cNamedArgs = 0; + if( ! bInit ) + { + OleInitialize( NULL ); + bInit = TRUE; + } + VariantInit( &RetVal ); VariantInit( &OleVal ); } } - //---------------------------------------------------------------------------// +//---------------------------------------------------------------------------// + +HB_FUNC( __HB_OLE_EXIT ) +{ + OleUninitialize(); +} + +//---------------------------------------------------------------------------// + HB_FUNC( ANSITOWIDE ) // ( cAnsiStr ) -> cWideStr { char *cString = hb_parc( 1 ); @@ -1486,7 +1529,7 @@ static void TraceLog( char * cFile, ... ) SysFreeString( bstrClassID ); - //TraceLog( NULL, "Result: %p\n", s_nOleError ); + // TraceLog( NULL, "Result: %p\n", s_nOleError ); if( hb_pcount() == 2 ) { @@ -1506,11 +1549,11 @@ static void TraceLog( char * cFile, ... ) if( SUCCEEDED( s_nOleError ) ) { - //TraceLog( NULL, "Class: %i\n", ClassID ); + // TraceLog( NULL, "Class: %i\n", ClassID ); s_nOleError = CoCreateInstance( (REFCLSID) &ClassID, NULL, CLSCTX_SERVER, (REFIID) riid, &pDisp ); - //TraceLog( NULL, "Result: %p\n", s_nOleError ); + // TraceLog( NULL, "Result: %p\n", s_nOleError ); } - + hb_retnl( ( LONG ) pDisp ); } diff --git a/harbour/contrib/ole2/win32ole.prg b/harbour/contrib/ole2/win32ole.prg index 661a1d3493..e66682a429 100644 --- a/harbour/contrib/ole2/win32ole.prg +++ b/harbour/contrib/ole2/win32ole.prg @@ -72,6 +72,7 @@ #define HB_CLS_NOTOBJECT + #include "hbclass.ch" #include "error.ch" @@ -82,20 +83,29 @@ FUNCTION CreateObject( cString ) RETURN TOleAuto():New( cString ) //----------------------------------------------------------------------------// + FUNCTION GetActiveObject( cString ) RETURN TOleAuto():GetActiveObject( cString ) //----------------------------------------------------------------------------// -//----------------------------------------------------------------------------// -// Called by hb_vmInit() by means of hb_vmDoInitOle() ONLY if OLE is linked-in -PROCEDURE HB_OleInit() + +init PROCEDURE HB_OleInit() __HB_OLE_INIT() RETURN //----------------------------------------------------------------------------// + +exit procedure HB_OleExit() + + __HB_OLE_EXIT() + +return + +//----------------------------------------------------------------------------// + CLASS VTWrapper DATA vt DATA Value @@ -205,7 +215,7 @@ METHOD New( uObj, cClass ) CLASS TOleAuto IF ::hObj != NIL RETURN HB_ExecFromArray( Self, "_New", HB_aParams() ) ENDIF - + IF ValType( uObj ) = 'C' ::hObj := CreateOleObject( uObj )