FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Saber Metodos de un CREATEOBJECT
Posts: 883
Joined: Tue Oct 11, 2005 11:57 AM
Saber Metodos de un CREATEOBJECT
Posted: Thu May 09, 2013 03:33 PM

Amigos

Como puedo saber con que metodos y/o datas cuento cuando creo un objeto con el CREATEOBJECT

Por ej.

oWord:=CreateObject( "word.Application" )
oword:PrintOut()
oWord:Select()

Como puedo listarlos para saber que funciones disponibles tengo, sea cual sea el objeto ?
De momento necesito saber de Word,Excel, y OUTLOOK, pero creo que debe haber alguna llamada generica que me indique cuales estan dependiendo del OBJETO,o no?

DEsde Chile
Adolfo

;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Saber Metodos de un CREATEOBJECT
Posted: Thu May 09, 2013 05:16 PM
Adolfo,

Aqui parece estar la documentación online del MSDN para el word.application:

http://msdn.microsoft.com/en-us/library/office/bb148369(v=office.12).aspx

Si lo que necesitas es revisarlo en tiempo de ejecución, es decir desde el propio EXE, dímelo y buscamos la forma de hacerlo :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 883
Joined: Tue Oct 11, 2005 11:57 AM
Re: Saber Metodos de un CREATEOBJECT
Posted: Thu May 09, 2013 07:56 PM

Antonio...

Precisamente a eso me referia, que hay que buscar en documentacion la lista de metodos o funciones disponibles, y no todos los productos tendran la misma delicadeza en describir todos sus metodos.

Puedo buscar los de MS, pero que pasa si quiero usar el Adobe Reader, o la suite LibreOffice, o Nero, etc.
Lo mas rapido, al menos durante la etapa de desarrollo seria algo como esto.

oWord:=CreateObject( "word.Application" )
oWord:ListFunctions() ---- un invento, pero quizas no sea tan dificil de implementar

Por lo pronto vere la documentacion que me mencionas, gracias

Desde Chile
Adolfo

;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Saber Metodos de un CREATEOBJECT
Posted: Fri May 10, 2013 08:01 AM
Una primera prueba implementando GetTypeInfoCount():

http://msdn.microsoft.com/en-us/library/aa910538.aspx

adolfo.prg
Code (fw): Select all Collapse
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Saber Metodos de un CREATEOBJECT
Posted: Fri May 10, 2013 08:53 AM
Haciendo pruebas con GetTypeInfo()

adolfo.prg
Code (fw): Select all Collapse
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Saber Metodos de un CREATEOBJECT
Posted: Fri May 10, 2013 08:54 AM
Un claro recordatorio muy facil de entender:

http://dudegizmo.blogspot.com.es/2004/09/understanding-iunknown-and-idispatch.html

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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Saber Metodos de un CREATEOBJECT
Posted: Fri May 10, 2013 09:27 AM
http://www.codeproject.com/Articles/13862/COM-in-plain-C-Part-2

// 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;
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 883
Joined: Tue Oct 11, 2005 11:57 AM
Re: Saber Metodos de un CREATEOBJECT
Posted: Fri May 10, 2013 12:47 PM

Antonio...

Que bien, asi podremos "investigar" cualquier objeto COM sin importar si tenemos info sobre sus funciones.

A la tarde reviso tus ejemplos.

A proposito de lo mismo, es bien potente la opcion del uso de objetos com , por lo que he leido y tu has posteado aqui, puede reducirnos y perfeccionar nuestro trabajo en distintas formas, aprovechandonos de sus metodos, sin tener que reinventar la rueda.

Gracias nuevamente.
Saludos

Desde Chile
Adolfo

;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Saber Metodos de un CREATEOBJECT
Posted: Fri May 10, 2013 01:46 PM

Adolfo,

No vendamos la piel del oso sin haberlo cazado primero... :-)

Aun falta para llegar a algo usable y no sabemos aún si funcionará.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Saber Metodos de un CREATEOBJECT
Posted: Fri May 10, 2013 03:14 PM
Ya vamos mostrando algo :-)



adolfo.prg
Code (fw): Select all Collapse
#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


http://www.codeproject.com/script/Content/ViewAssociatedFile.aspx?rzp=%2FKB%2FCOM%2Fdispexsinkconnector%2F%2Fdispexsinkconnector_src.zip&zep=DispExSinkConnector.h&obid=3326&obtid=2&ovid=1
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Saber Metodos de un CREATEOBJECT
Posted: Fri May 10, 2013 03:32 PM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Saber Metodos de un CREATEOBJECT
Posted: Fri May 10, 2013 04:14 PM
Avanzando un poquito más...

Code (fw): Select all Collapse
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 883
Joined: Tue Oct 11, 2005 11:57 AM
Re: Saber Metodos de un CREATEOBJECT
Posted: Fri May 10, 2013 04:43 PM

Ja Ja Ja

Antonio... pues parece que si es usable y que funciona.

Como lo haces, no se, pero bien por nosotros que siempre encontramos ayuda y/o respuestas por aqui.

Saludos, esperando la version BETA 1.0 :-)

Desde Chile
Adolfo

;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Posts: 1144
Joined: Mon Feb 05, 2007 07:15 PM
Re: Saber Metodos de un CREATEOBJECT
Posted: Fri May 10, 2013 05:33 PM

Antonio, Muy interesante,
esto me hace recordar el viejo NG de clipper,
pero esto seria sobre un objeto en especifico,
ademas de conocer sus datas, metodos ... ,
en otra columna poner el significado de cada elemento
y un ejemplo de uso. jejeje, no quiero nada vdd?

oExcel := CreateObject( "excel.application" )

ELEMENTO, SIGNIFICADO, EJEMPLO DE USO

saludos.

Cesar Cortes Cruz

SysCtrl Software

Mexico



' Sin +- FWH es mejor "