Page 1 of 1

OutputDebugString(

Posted: Tue Sep 30, 2008 7:58 pm
by Vladimir Zorrilla
Amigos Leyendo en http://codigo-base.blogspot.com/ hay un tema que dice Depurando en Windows

Y precisa que podemos invocar desde FW esta funcion del API

IF File( "test.txt" )
OutputDebugString( "El archivo existe" + hb_osnewline() )
ELSE
OutputDebugString( "El archivo no existe" + hb_osnewline() )
ENDIF

Al incluir esto en nuestro codigo fuente realmente no estaremos viendo nada, en primer lugar antes de ejecutar nuestro programa debemos tener en ejecucion dbwin32.exe, este programa se encarga de mostrar en pantalla la informacion pasada como parametro a la funcion
OutputDebugString().


CUando pongo esta fuincion me sale un error

UNRESOLVED EXTERNAL hb_fun_OutputDebugString

que LIB contiene el soporte a esta funcion del API
que deba poner en mi lnk.

Gracias

Posted: Tue Sep 30, 2008 9:07 pm
by Antonio Linares
Vladimir,

Aqui la tienes:

Code: Select all

#include "FiveWin.ch" 

function Main() 

   OutputDebugString( "Test" ) 

return nil 

#pragma BEGINDUMP 

#include <hbapi.h> 
#include <windows.h>

HB_FUNC( OUTPUTDEBUGSTRING ) 
{ 
   OutputDebugString( hb_parc( 1 ) );    
} 

#pragma ENDDUMP

Posted: Tue Sep 30, 2008 9:11 pm
by Antonio Linares
Y aqui una copia de DbWin32.zip para que la tengamos siempre a mano :-)

www.fivetechsoft.com/files/utilities/dbwin32.zip

Posted: Tue Sep 30, 2008 11:16 pm
by carlos vargas
Funciona de la siguiente forma, en cualquier parte de su programa use

Code: Select all

??? date(), time(), version(), 1+1
:-)

archivo .ch

Code: Select all

#xcommand ??? <xData> [, <xDataN> ] => OutPutDebugString( <xData> ) ;
                                   	[; OutPutDebugString( <xDataN>) ]

archivo .prg

Code: Select all

FUNCTION OutPutDebugString(xVal)
   OutPutDebugStringC( HB_ValToStr(xVal) )
RETURN NIL

#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"
#include "hbapiitm.h"
#include "hbapierr.h"


HB_FUNC( OUTPUTDEBUGSTRINGC )
{
   OutputDebugStringA( hb_parc( 1 ) );
}

HB_FUNC ( EXITPROCESS )
{
  ExitProcess( 0 ) ;
}

#pragma ENDDUMP

Posted: Wed Oct 01, 2008 1:48 pm
by Carlos Mora
Gente,
tengo una definición de comando que uso hace bastante tiempo, que te pasa no solo el valor sino tambien la lineas de la funcion donde se invoca, y la expresion evaluada. Al ser un comando, se puede hacer una definición nula cuando se compila la version final.

Code: Select all


#ifdef __RELEASE__

# xtranslate DEBUG <clauses, ...> =>

#else

#translate ASSTRING( <x> ) => If( <x> == NIL, 'NIL', Transform( <x> , NIL ) ) + CRLF

#xcommand DEBUG <cString1>[, <cStringN>] ;
         => ;
          OutputDebugString( ProcName() +"("+LTrim(Str(ProcLine())) +") - " ) ; OutputDebugString( <"cString1">+" ("+ValType( <cString1> )+"): " ) ; OutputDebugString( ASSTRING( <cString1> ) ) ;
          [ ; OutputDebugString( ProcName() +"("+LTrim(Str(ProcLine())) +") - " ) ; OutputDebugString( <"cStringN">+" ("+ValType( <cStringN> )+"): " ) ; OutputDebugString( ASSTRING( <cStringN> ) ) ]

#endif

Es interesante tambien el uso de transform para hacer string casi cualquier cosa, pero no es el tema a tratar ;)

Por ejemplo, si ponemos en la línea 895 de bitmap.prg la sig. línea,

Code: Select all


   DEBUG ::lScroll, nVisHeight, nVisWidth, ::hBitmap, ::oVScroll

Un ejemplo de lo que obtendremos en dBWin32 podría ser:

Code: Select all

TBITMAP:SCROLLADJUST(895) - ::lScroll (L): F
TBITMAP:SCROLLADJUST(895) - nVisHeight (N):        329
TBITMAP:SCROLLADJUST(895) - nVisWidth (N):        450
TBITMAP:SCROLLADJUST(895) - ::hBitmap (N):          -1509616760
TBITMAP:SCROLLADJUST(895) - ::oVScroll (U): NIL
TBITMAP:SCROLLADJUST(895) - ::lScroll (L): F
TBITMAP:SCROLLADJUST(895) - nVisHeight (N):        656
TBITMAP:SCROLLADJUST(895) - nVisWidth (N):       1024
TBITMAP:SCROLLADJUST(895) - ::hBitmap (N): -536539779
TBITMAP:SCROLLADJUST(895) - ::oVScroll (U): NIL

Esto nos ayuda a saber Exactamente que estamos viendo, porque si imprimimos solo el valor en outdebug no sabremos exactamente a que variable o campo corresponde, ni a que punto del programa corresponde si tenemos muchos valores.

Y todo esto se quita con añadir un /D__RELEASE__ en la línea de compilación de los prgs!

Espero que les sea tan útil como a mí,

Carlos.

Posted: Wed Oct 01, 2008 2:02 pm
by Antonio Linares
Carlos,

Muy buena aportación. Gracias! :-)