#include "FiveWin.ch"
function Main()
local o := CreateObject( "ADODB.Recordset" )
MsgInfo( GetTypeInfoCount( o:hObj ) )
return nil
#pragma BEGINDUMP
#include <hbapi.h>
#include "c:\harbour\contrib\hbwin\hbwinole.h"
HB_FUNC( GETTYPEINFOCOUNT )
{
IDispatch * pDisp = hb_oleParam( 1 );
HRESULT lOleError;
UINT ctinfo;
lOleError = HB_VTBL( pDisp )->GetTypeInfoCount( HB_THIS( pDisp ), &ctinfo );
hb_retnl( ( lOleError == S_OK ) ? ctinfo: -1 );
}
#pragma ENDDUMP
#include "FiveWin.ch"
function Main()
local o := CreateObject( "ADODB.Recordset" )
MsgInfo( GetTypeInfoCount( o:hObj ) )
MsgInfo( GetTypeInfo( o:hObj ) )
return nil
#pragma BEGINDUMP
#include <hbapi.h>
#include "c:\harbour\contrib\hbwin\hbwinole.h"
HB_FUNC( GETTYPEINFOCOUNT )
{
IDispatch * pDisp = hb_oleParam( 1 );
HRESULT lOleError;
UINT ctinfo;
lOleError = HB_VTBL( pDisp )->GetTypeInfoCount( HB_THIS( pDisp ), &ctinfo );
hb_retnl( ( lOleError == S_OK ) ? ctinfo: -1 );
}
HB_FUNC( GETTYPEINFO )
{
IDispatch * pDisp = hb_oleParam( 1 );
ITypeInfo * pInfo;
HRESULT lOleError;
lOleError = HB_VTBL( pDisp )->GetTypeInfo( HB_THIS( pDisp ), 0, 0, &pInfo );
HB_VTBL( pInfo )->Release( HB_THIS( pInfo ) );
hb_retnl( ( lOleError == S_OK ) ? 1: 0 );
}
#pragma ENDDUMP
When we create a COM object it has our new custom interface that contains our defined methods. This interface has to inherit from IDispatch that in turn inherits from IUknown.
IDispatch is the main interface that COM uses to expose members of our COM object. It exposes four different methods that help external applications to learn about our COM object's methods:
1. GetTypeInfoCount - Returns 0 if there is no type information available or 1 if there is a type information.
2. GetTypeInfo - Gets a type information interface if exists to explore this interface.
3. GetIDsOfNames - Takes a method name array and returns a method id array
4. Invoke - Invokes a method by its method id.
So if we take a look at our COM object interface "vtable" witch holds pointers to the object's methods we will see:
- 3 IUknown methods (QueryInterface, AddRef, and Release).
- 4 IDispatch methods (GetTypeInfoCount, GetTypeInfo, GetIDsOfNames, and Invoke).
- Any number of our custom methods.
// IUnknown functions
STDMETHOD (QueryInterface) (THIS_ REFIID, void **) PURE;
STDMETHOD_ (ULONG, AddRef) (THIS) PURE;
STDMETHOD_ (ULONG, Release) (THIS) PURE;
// IDispatch functions
STDMETHOD_ (ULONG, GetTypeInfoCount)(THIS_ UINT *) PURE;
STDMETHOD_ (ULONG, GetTypeInfo) (THIS_ UINT, LCID, ITypeInfo **) PURE;
STDMETHOD_ (ULONG, GetIDsOfNames) (THIS_ REFIID, LPOLESTR *,
UINT, LCID, DISPID *) PURE;
STDMETHOD_ (ULONG, Invoke) (THIS_ DISPID, REFIID,
LCID, WORD, DISPPARAMS *,
VARIANT *, EXCEPINFO *, UINT *) PURE;
#include "FiveWin.ch"
function Main()
local o := CreateObject( "ADODB.Recordset" )
// MsgInfo( GetTypeInfoCount( o:hObj ) )
XBROWSER GetTypeInfo( o:hObj ) TITLE "Properties"
return nil
#pragma BEGINDUMP
#include <hbapi.h>
#include "c:\harbour\contrib\hbwin\hbwinole.h"
HB_FUNC( GETTYPEINFOCOUNT )
{
IDispatch * pDisp = hb_oleParam( 1 );
HRESULT lOleError;
UINT ctinfo;
lOleError = HB_VTBL( pDisp )->GetTypeInfoCount( HB_THIS( pDisp ), &ctinfo );
hb_retnl( ( lOleError == S_OK ) ? ctinfo: -1 );
}
static LPSTR WideToAnsi( LPWSTR cWide )
{
WORD wLen;
LPSTR cString = NULL;
wLen = WideCharToMultiByte( CP_ACP, 0, cWide, -1, cString, 0, NULL, NULL );
cString = ( LPSTR ) hb_xgrab( wLen );
WideCharToMultiByte( CP_ACP, 0, cWide, -1, cString, wLen, NULL, NULL );
return cString;
}
HB_FUNC( GETTYPEINFO )
{
IDispatch * pDisp = hb_oleParam( 1 );
ITypeInfo * pInfo;
HRESULT lOleError;
TYPEATTR * pta;
int i;
lOleError = HB_VTBL( pDisp )->GetTypeInfo( HB_THIS( pDisp ), 0, 0, &pInfo );
lOleError = HB_VTBL( pInfo )->GetTypeAttr( HB_THIS( pInfo ), &pta );
hb_reta( pta->cFuncs );
for( i = 0; i < pta->cFuncs; i++ )
{
BSTR bsName;
FUNCDESC * pfd;
unsigned int uiNames = 0;
char * pszName;
lOleError = HB_VTBL( pInfo )->GetFuncDesc( HB_THIS( pInfo ), i, &pfd );
lOleError = HB_VTBL( pInfo )->GetNames( HB_THIS( pInfo ), pfd->memid, &bsName, 1, &uiNames );
pszName = WideToAnsi( bsName );
hb_storvclen( pszName, strlen( pszName ), -1, i + 1 );
hb_xfree( ( void * ) pszName );
HB_VTBL( pInfo )->ReleaseFuncDesc( HB_THIS( pInfo ), pfd );
}
HB_VTBL( pInfo )->Release( HB_THIS( pInfo ) );
}
#pragma ENDDUMP
#include "FiveWin.ch"
function Main()
local o := CreateObject( "ADOX.Table" )
// local pTypeInfo
if GetTypeInfoCount( o:hObj ) == 1 // There is info
// pTypeInfo = TOleAuto():New( GetTypeInfo( o:hObj ) )
if Len( GetTypeVars( o:hObj ) ) > 0
XBROWSER GetTypeVars( o:hObj ) TITLE "Variables"
endif
XBROWSER GetTypeFuncs( o:hObj ) TITLE "Functions"
endif
return nil
#pragma BEGINDUMP
#include <hbapi.h>
#include "c:\harbour\contrib\hbwin\hbwinole.h"
HB_FUNC( GETTYPEINFOCOUNT )
{
IDispatch * pDisp = hb_oleParam( 1 );
HRESULT lOleError;
UINT ctinfo;
lOleError = HB_VTBL( pDisp )->GetTypeInfoCount( HB_THIS( pDisp ), &ctinfo );
hb_retnl( ( lOleError == S_OK ) ? ctinfo: -1 );
}
static LPSTR WideToAnsi( LPWSTR cWide )
{
WORD wLen;
LPSTR cString = NULL;
wLen = WideCharToMultiByte( CP_ACP, 0, cWide, -1, cString, 0, NULL, NULL );
cString = ( LPSTR ) hb_xgrab( wLen );
WideCharToMultiByte( CP_ACP, 0, cWide, -1, cString, wLen, NULL, NULL );
return cString;
}
HB_FUNC( GETTYPEINFO )
{
IDispatch * pDisp = hb_oleParam( 1 );
ITypeInfo * pInfo;
if( HB_VTBL( pDisp )->GetTypeInfo( HB_THIS( pDisp ), 0, 0, &pInfo ) == S_OK )
hb_oleItemPut( hb_stackReturnItem(), ( IDispatch * ) pInfo );
else
hb_ret();
}
HB_FUNC( GETTYPEVARS )
{
IDispatch * pDisp = hb_oleParam( 1 );
ITypeInfo * pInfo;
HRESULT lOleError;
TYPEATTR * pta;
int i;
lOleError = HB_VTBL( pDisp )->GetTypeInfo( HB_THIS( pDisp ), 0, 0, &pInfo );
lOleError = HB_VTBL( pInfo )->GetTypeAttr( HB_THIS( pInfo ), &pta );
hb_reta( pta->cVars );
for( i = 0; i < pta->cVars; i++ )
{
BSTR bsName;
VARDESC * pVar;
char * pszName;
lOleError = HB_VTBL( pInfo )->GetVarDesc( HB_THIS( pInfo ), i, &pVar );
lOleError = HB_VTBL( pInfo )->GetDocumentation( HB_THIS( pInfo ), pVar->memid, &bsName, NULL, NULL, NULL );
pszName = WideToAnsi( bsName );
hb_storvclen( pszName, strlen( pszName ), -1, i + 1 );
hb_xfree( ( void * ) pszName );
HB_VTBL( pInfo )->ReleaseVarDesc( HB_THIS( pInfo ), pVar );
}
HB_VTBL( pInfo )->Release( HB_THIS( pInfo ) );
}
HB_FUNC( GETTYPEFUNCS )
{
IDispatch * pDisp = hb_oleParam( 1 );
ITypeInfo * pInfo;
HRESULT lOleError;
TYPEATTR * pta;
int i;
lOleError = HB_VTBL( pDisp )->GetTypeInfo( HB_THIS( pDisp ), 0, 0, &pInfo );
lOleError = HB_VTBL( pInfo )->GetTypeAttr( HB_THIS( pInfo ), &pta );
hb_reta( pta->cFuncs );
for( i = 0; i < pta->cFuncs; i++ )
{
BSTR bsName;
FUNCDESC * pfd;
char * pszName;
lOleError = HB_VTBL( pInfo )->GetFuncDesc( HB_THIS( pInfo ), i, &pfd );
// lOleError = HB_VTBL( pInfo )->GetNames( HB_THIS( pInfo ), pfd->memid, &bsName, 1, &uiNames );
lOleError = HB_VTBL( pInfo )->GetDocumentation( HB_THIS( pInfo ), pfd->memid, &bsName, NULL, NULL, NULL );
pszName = WideToAnsi( bsName );
hb_storvclen( pszName, strlen( pszName ), -1, i + 1 );
hb_xfree( ( void * ) pszName );
HB_VTBL( pInfo )->ReleaseFuncDesc( HB_THIS( pInfo ), pfd );
}
HB_VTBL( pInfo )->Release( HB_THIS( pInfo ) );
}
#pragma ENDDUMP
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: Google [Bot] and 110 guests