FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour DLL32 function
Posts: 113
Joined: Wed Jan 10, 2007 08:43 PM
DLL32 function
Posted: Fri Mar 28, 2008 05:03 PM

Amigos:
Agradecer茅 quien me pueda orientar o indicar donde obtener informaci贸n en como manejar DLL32 Function ya que necesito de 茅sta para poder acceder al API de Windows.
Mil gracias de antemano.

David Lagos S.
Coquimbo-Chile
www.wificafe.cl
webmaster@wificafe.cl
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
DLL32 function
Posted: Fri Mar 28, 2008 06:40 PM

David,

A que funci贸n del API de Windows quieres acceder ?

Haz una b煤squeda en estos foros por DLL AND function y te aparecer谩n muchos ejemplos

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 654
Joined: Mon May 29, 2006 03:14 PM
DLL32 function
Posted: Fri Mar 28, 2008 08:05 PM
En el fichero DLL.CH esta parte de lo que buscas:

#xcommand DLL [<static:STATIC>] FUNCTION <FuncName>( [ <uParam1> AS <type1> ] ;
                                                     [, <uParamN> AS <typeN> ] ) ;
             AS <return> [<pascal:PASCAL>] [ FROM <SymName> ] LIB <*DllName*> ;
       => ;
          [<static>] function <FuncName>( [NOREF(<uParam1>)] [,NOREF(<uParamN>)] ) ;;
             local hDLL := If( ValType( <DllName> ) == "N", <DllName>, LoadLibrary( <(DllName)> ) ) ;;
             local uResult ;;
             local cFarProc ;;
             if Abs( hDLL ) > 32 ;;
                cFarProc = GetProcAddress( hDLL,;
                If( [ Empty( <SymName> ) == ] .t., <(FuncName)>, <SymName> ),;
                [<.pascal.>], <return> [,<type1>] [,<typeN>] ) ;;
                uResult = CallDLL( cFarProc [,<uParam1>] [,<uParamN>] ) ;;
                If( ValType( <DllName> ) == "N",, FreeLibrary( hDLL ) ) ;;
             else ;;
                MsgAlert( "Error code: " + LTrim( Str( hDLL ) ) + " loading " + ;
                If( ValType( <DllName> ) == "C", <DllName>, Str( <DllName> ) ) ) ;;
             end ;;
          return uResult


#xcommand DLL32 [<static:STATIC>] FUNCTION <FuncName>( [ <uParam1> AS <type1> ] ;
                                                      [, <uParamN> AS <typeN> ] ) ;
             AS <return> [<pascal:PASCAL>] [ FROM <SymName> ] LIB <*DllName*> ;
       => ;
          [<static>] function <FuncName>( [NOREF(<uParam1>)] [,NOREF(<uParamN>)] ) ;;
             local hDLL := If( ValType( <DllName> ) == "N", <DllName>, LoadLib32( <(DllName)> ) ) ;;
             local uResult ;;
             local cFarProc ;;
             if Abs( hDLL ) <= 32 ;;
                MsgAlert( "Error code: " + LTrim( Str( hDLL ) ) + " loading " + <DllName> ) ;;
             else ;;
                cFarProc = GetProc32( hDLL,;
                If( [ Empty( <SymName> ) == ] .t., <(FuncName)>, <SymName> ),;
                [<.pascal.>], <return> [,<type1>] [,<typeN>] ) ;;
                uResult = CallDLL32( cFarProc [,<uParam1>] [,<uParamN>] ) ;;
                If( ValType( <DllName> ) == "N",, FreeLib32( hDLL ) ) ;;
             end ;;
          return uResult

#endif
Mi abuelo dec铆a: Los aviones vuelan porque Dios quiere, y los helic贸pteros ni Dios sabe porque vuelan.

FWH 16.02, xHarbour 1.2.3, Harbour 3.2.0, WorkShop 4.5, AJ Make 0.30, Borlan BCC 7.00, VisualStudio 2013
Posts: 113
Joined: Wed Jan 10, 2007 08:43 PM
DLL32 function
Posted: Fri Mar 28, 2008 08:23 PM
JmGarcia wrote:En el fichero DLL.CH esta parte de lo que buscas:

#xcommand DLL [<static:STATIC>] FUNCTION <FuncName>( [ <uParam1> AS <type1> ] ;
                                                     [, <uParamN> AS <typeN> ] ) ;
             AS <return> [<pascal:PASCAL>] [ FROM <SymName> ] LIB <*DllName*> ;
       => ;
          [<static>] function <FuncName>( [NOREF(<uParam1>)] [,NOREF(<uParamN>)] ) ;;
             local hDLL := If( ValType( <DllName> ) == "N", <DllName>, LoadLibrary( <(DllName)> ) ) ;;
             local uResult ;;
             local cFarProc ;;
             if Abs( hDLL ) > 32 ;;
                cFarProc = GetProcAddress( hDLL,;
                If( [ Empty( <SymName> ) == ] .t., <(FuncName)>, <SymName> ),;
                [<.pascal.>], <return> [,<type1>] [,<typeN>] ) ;;
                uResult = CallDLL( cFarProc [,<uParam1>] [,<uParamN>] ) ;;
                If( ValType( <DllName> ) == "N",, FreeLibrary( hDLL ) ) ;;
             else ;;
                MsgAlert( "Error code: " + LTrim( Str( hDLL ) ) + " loading " + ;
                If( ValType( <DllName> ) == "C", <DllName>, Str( <DllName> ) ) ) ;;
             end ;;
          return uResult


#xcommand DLL32 [<static:STATIC>] FUNCTION <FuncName>( [ <uParam1> AS <type1> ] ;
                                                      [, <uParamN> AS <typeN> ] ) ;
             AS <return> [<pascal:PASCAL>] [ FROM <SymName> ] LIB <*DllName*> ;
       => ;
          [<static>] function <FuncName>( [NOREF(<uParam1>)] [,NOREF(<uParamN>)] ) ;;
             local hDLL := If( ValType( <DllName> ) == "N", <DllName>, LoadLib32( <(DllName)> ) ) ;;
             local uResult ;;
             local cFarProc ;;
             if Abs( hDLL ) <= 32 ;;
                MsgAlert( "Error code: " + LTrim( Str( hDLL ) ) + " loading " + <DllName> ) ;;
             else ;;
                cFarProc = GetProc32( hDLL,;
                If( [ Empty( <SymName> ) == ] .t., <(FuncName)>, <SymName> ),;
                [<.pascal.>], <return> [,<type1>] [,<typeN>] ) ;;
                uResult = CallDLL32( cFarProc [,<uParam1>] [,<uParamN>] ) ;;
                If( ValType( <DllName> ) == "N",, FreeLib32( hDLL ) ) ;;
             end ;;
          return uResult

#endif


Gracias...esoy ya lo hab铆a visto
El tema es que no hayo como acceder a una funci贸n del api para realizar pruebas.
Estoy intentando obtener las impresoras que tengo instaladas en el pc.
Si utilizo:

aGetPrinters()

funciona ok...pero estoy intentando hacerlo de la forma dif铆cil para poder entender como acceder a las funciones del api. Tengo instalado el sdk de windows para obtener las refencias a las funciones que necesito.

Este es el c贸digo que estoy utilizando y no me devuelve el arreglo con los datos:


#include "fivewin.ch"
//#include "winspool.h"
#define PRINTER_ENUM_DEFAULT     0x00000001
#define PRINTER_ENUM_LOCAL       0x00000002
#define PRINTER_ENUM_CONNECTIONS 0x00000004
#define PRINTER_ENUM_FAVORITE    0x00000004
#define PRINTER_ENUM_NAME        0x00000008
#define PRINTER_ENUM_REMOTE      0x00000010
#define PRINTER_ENUM_SHARED      0x00000020
#define PRINTER_ENUM_NETWORK     0x00000040

FUNCTION Main()
	LOCAL pThread, aPrinters:=Array()
	IF MsgYesNo("驴Des茅a mostrar las impresoras del sistema?")
		EnumPrinters(PRINTER_ENUM_NAME,,1,@aPrinters)
                aPrinters:=EnumPrinters(PRINTER_ENUM_NAME,,1)
		//aPrinters:=aGetPrinters()
		FOR n := 1 TO Len(aPrinters)
			MsgInfo(aPrinters[n])
		NEXT
	ENDIF

RETURN NIL

DLL32 FUNCTION EnumPrinters( Flags AS DWORD, Name AS LPSTR, Level AS DWORD, @aPrinters AS BYTE, cbBuf AS DWORD, @pcbNeeded AS DWORD, @pcReturned AS DWORD) ;
	AS LONG PASCAL FROM "EnumPrinters" LIB "winspool.drv"


Este es el link a la referencia del api que quiero probar para empezar a entender todo este cuento:

http://msdn2.microsoft.com/en-us/library/ms536005(VS.85).aspx


Gracias por la ayuda que me puedan brindar.
David Lagos S.
Coquimbo-Chile
www.wificafe.cl
webmaster@wificafe.cl
Posts: 113
Joined: Wed Jan 10, 2007 08:43 PM
DLL32 function
Posted: Fri Mar 28, 2008 10:06 PM
Encontr茅 un ejemplo en un foro de no se donde y funcion贸 lo que buscaba, pero 驴es tan complicado el poder trabajar con el api de windows?....y soy menos que novato en C++....ufff
pongo el c贸digo por si a alguien le sirve.
Ojal谩 alguien m谩s aporte sobre esto...imag铆nense que esto es solo la punta del iceberg para mi ya que la finalidad entre otras es poder detectar cuando llega una impresi贸n a una impresora "X", pausar la impresi贸n y autorizar su salida en forma manual.

#include "hbclass.ch"
#include "fivewin.ch"
FUNCTION Main()
	IF MsgYesNo("驴Des茅a mostrar las impresoras del sistema?")
		aPrinters:=WinGetPrinters()
		Msginfo( Len(aPrinters), "Impresoras Encontradas")
		MsgInfo( WinDefaultPrinter(), "Impresora por Defecto")
		FOR n := 1 TO Len(aPrinters)
			MsgInfo(aPrinters[n])
		NEXT
	ENDIF

RETURN NIL

STATIC FUNCTION WinGetPrinters()
  LOCAL aPrn:= {}, nStart:=1, cPrinters, nStop,nPos, cPrn
  cPrinters:= ENUMPRINTERS()+';'
  nStop:= LEN(cPrinters)+1
  DO WHILE nStart< nStop
    nPos:=AT(';',cPrinters,nStart)
    IF !EMPTY(cPrn:= SUBSTR(cPrinters,nStart,nPos-nStart))
      AADD(aPrn,cPrn)
    ENDIF
    nStart:= nPos+1
  ENDDO
RETURN(aPrn)

#pragma BEGINDUMP

#undef UNICODE

#include <windows.h>
#include "hbapi.h"
#include "hbvm.h"
#include "hbstack.h"
#include "hbapiitm.h"

#define MAX_FILE_NAME 1024
#define BIG_BUFFER (1024*32)

HB_FUNC ( ENUMPRINTERS)
{
  UCHAR *Result ;
  DWORD x, Flags = PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS  ;
  LPSTR Name = NULL ;
  DWORD Level = 5 ;
  PRINTER_INFO_5 *pPrinterEnum, *pFree;
  PRINTER_INFO_4 *pPrinterEnum4, *pFree4;
  DWORD cbBuf  ;
  DWORD BytesNeeded=0 ;
  DWORD NumOfPrinters=0 ;
  OSVERSIONINFO osvi ;  //  altered to check Windows Version
  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  GetVersionEx (&osvi);
  if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
  {
    Level = 4 ;
    EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum4,0,&BytesNeeded,&NumOfPrinters) ;
    if (BytesNeeded > 0)
    {
      Result = (UCHAR *)  hb_xgrab(BytesNeeded) ;
      *Result = '\0' ;
      pFree4 = pPrinterEnum4 = (PRINTER_INFO_4 *)  hb_xgrab(BytesNeeded) ;
      cbBuf = BytesNeeded ;
      if (EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum4,cbBuf,&BytesNeeded,&NumOfPrinters))
      {
        for (x=0 ; x< NumOfPrinters ; x++, pPrinterEnum4++ )
        {
          strcat(Result,pPrinterEnum4->pPrinterName) ;
          strcat(Result,";") ;
        }
      }
      hb_retc(Result) ;
      hb_xfree(Result) ;
      hb_xfree(pFree4) ;
    }
    else
      hb_retc("") ;
  }
  else
   {
    EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum,0,&BytesNeeded,&NumOfPrinters) ;
    if (BytesNeeded > 0)
    {
      Result = (UCHAR *)  hb_xgrab(BytesNeeded) ;
      *Result = '\0' ;
      pFree = pPrinterEnum = (PRINTER_INFO_5 *)  hb_xgrab(BytesNeeded) ;
      cbBuf = BytesNeeded ;
      if (EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum,cbBuf,&BytesNeeded,&NumOfPrinters))
      {
        for (x=0 ; x< NumOfPrinters ; x++, pPrinterEnum++ )
        {
          strcat(Result,pPrinterEnum->pPrinterName) ;
          strcat(Result,";") ;
        }
      }
      hb_retc(Result) ;
      hb_xfree(Result) ;
      hb_xfree(pFree) ;
    }
    else
      hb_retc("") ;
  }
}

HB_FUNC( WINDEFAULTPRINTER )
{
  DWORD x, y ;
  UCHAR lpReturnedString[MAX_FILE_NAME] ;
  x = GetProfileString("windows","device","",lpReturnedString,MAX_FILE_NAME-1);
  y = 0 ;
  while ( y < x && lpReturnedString[y] != ',' )
    y++ ;
  hb_retclen(lpReturnedString,y) ;
}
#pragma ENDDUMP


Espero le sirva a alguien.
Saludos

P.D.: new_indika si ves esto te mande un mail a tu correo a ver si te puedo consultar algunas cosillas.
David Lagos S.
Coquimbo-Chile
www.wificafe.cl
webmaster@wificafe.cl
Posts: 654
Joined: Mon May 29, 2006 03:14 PM
DLL32 function
Posted: Fri Mar 28, 2008 10:11 PM
metaldrummer wrote:DLL32 FUNCTION EnumPrinters( Flags AS DWORD, Name AS LPSTR, Level AS DWORD, @aPrinters AS BYTE, cbBuf AS DWORD, @pcbNeeded AS DWORD, @pcReturned AS DWORD) ;
AS LONG PASCAL FROM "EnumPrinters" LIB "winspool.drv"

En la definicion DLL32 no tienes que poner las "arrobas" (@) solo cuando la amas a la funci贸n.
Mi abuelo dec铆a: Los aviones vuelan porque Dios quiere, y los helic贸pteros ni Dios sabe porque vuelan.

FWH 16.02, xHarbour 1.2.3, Harbour 3.2.0, WorkShop 4.5, AJ Make 0.30, Borlan BCC 7.00, VisualStudio 2013
Posts: 113
Joined: Wed Jan 10, 2007 08:43 PM
DLL32 function
Posted: Mon Mar 31, 2008 03:53 PM
JmGarcia wrote:
metaldrummer wrote:DLL32 FUNCTION EnumPrinters( Flags AS DWORD, Name AS LPSTR, Level AS DWORD, @aPrinters AS BYTE, cbBuf AS DWORD, @pcbNeeded AS DWORD, @pcReturned AS DWORD) ;
AS LONG PASCAL FROM "EnumPrinters" LIB "winspool.drv"

En la definicion DLL32 no tienes que poner las "arrobas" (@) solo cuando la amas a la funci贸n.


Mira:
Tengo este c贸digo:
include "fivewin.ch"
#define PRINTER_ENUM_DEFAULT     0x00000001
#define PRINTER_ENUM_LOCAL       0x00000002
#define PRINTER_ENUM_CONNECTIONS 0x00000004
#define PRINTER_ENUM_FAVORITE    0x00000004
#define PRINTER_ENUM_NAME        0x00000008
#define PRINTER_ENUM_REMOTE      0x00000010
#define PRINTER_ENUM_SHARED      0x00000020
#define PRINTER_ENUM_NETWORK     0x00000040

FUNCTION Main()
   LOCAL aPrinters
   IF MsgYesNo("驴Des茅a mostrar las impresoras del sistema?")
      EnumPrinters(PRINTER_ENUM_NAME,NILL,1,@aPrinters,, @nNecesitado, @nRetornado)
      FOR n := 1 TO Len(aPrinters)
         MsgInfo(aPrinters[n,1])
      NEXT
   ENDIF

RETURN NIL

DLL32 FUNCTION EnumPrinters( Flags AS DWORD, Name AS LPSTR, Level AS DWORD, aPrinters AS BYTE, cbBuf AS DWORD, pcbNeeded AS DWORD, pcReturned AS DWORD) ;
   AS BOOL PASCAL FROM "EnumPrinters" LIB "winspool.drv"


Para este c贸digo siempre me retorna aPrinters como NILL lo mismo que las otras variables por referencia ya que nNecesitado debiera devolver el n煤mero necesitado de espacio para almacenar la informaci贸n en aPrinters que nunca recibe un arreglo como indica la documentaci贸n.
En qu茅 podr茅 estar fallando?
Saludos
David Lagos S.
Coquimbo-Chile
www.wificafe.cl
webmaster@wificafe.cl
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
DLL32 function
Posted: Mon Mar 31, 2008 08:38 PM

David,

La funci贸n EnumPrinters() del API tiene un nivel de complejidad que dificilmente puede tratarse con el comando DLL FUNCTION desde PRG.

La funci贸n que has publicado en C, te funciona ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 113
Joined: Wed Jan 10, 2007 08:43 PM
DLL32 function
Posted: Mon Mar 31, 2008 09:48 PM
La funci贸n EnumPrinters() del API tiene un nivel de complejidad que dificilmente puede tratarse con el comando DLL FUNCTION desde PRG.

La funci贸n que has publicado en C, te funciona ?


La funci贸n que encontr茅 en internet que originalmente creo estaba orientada a alaska xbase++ funciona de lujo....

Mi pregunta es: porqu茅 la DLL32 funciona en ciertas funciones y en otras no?...
Lamentablemente estoy reci茅n comenzando a leer documentaci贸n de c++ y la verdad que soy menos que novato.
Saludos
David Lagos S.
Coquimbo-Chile
www.wificafe.cl
webmaster@wificafe.cl
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
DLL32 function
Posted: Mon Mar 31, 2008 10:17 PM

David,

DLL FUNCTION ... permite un acceso relativamente simple a funciones que reciben unos par谩metros y devuelven un resultado.

En el caso de EnumPrinters() se rellenan unas estructuras desde C, por la misma funci贸n EnumPrinters(), y hay que manejar la informaci贸n de esas estructuras, desde bajo nivel.

Teoricamente se podr铆a hacer usando DLL FUNCTION, pero puede resultar m谩s complejo que hacerlo usando C directamente.

Est谩s ya familiarizado con el uso de estructuras en lenguaje C ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 113
Joined: Wed Jan 10, 2007 08:43 PM
DLL32 function
Posted: Mon Mar 31, 2008 11:12 PM
Antonio Linares wrote:David,

DLL FUNCTION ... permite un acceso relativamente simple a funciones que reciben unos par谩metros y devuelven un resultado.

En el caso de EnumPrinters() se rellenan unas estructuras desde C, por la misma funci贸n EnumPrinters(), y hay que manejar la informaci贸n de esas estructuras, desde bajo nivel.

Teoricamente se podr铆a hacer usando DLL FUNCTION, pero puede resultar m谩s complejo que hacerlo usando C directamente.

Est谩s ya familiarizado con el uso de estructuras en lenguaje C ?


Estimado Antonio:
Estoy reci茅n comenzando a leer algo de C y obviamente entiendo que su curva de aprendizaje es m谩s lenta que otros lenguajes.
Vi que hay un DllCall de xharbour que permite llamar a las funciones del API, pero cuando intento llamar al DLL la aplicaci贸n no corre. Seguro que estoy haciendo todo o casi todo mal por mi pr谩cticamente nulo conocimiento de C. Claro que para m铆 es un gran reto desarrollar esta aplicaci贸n y si esto me significa tener que aprender C y C++ GENIAL ya que es algo que he anhelado por mucho tiempo. Lo divertido es que ahora tengo que hacerlo bajo presi贸n.
Voy a intentar leer un poco un manual que baj茅 de internet orientado a Borland C++ y agradecer茅 tu ayuda y la de cualquier colega del foro.
Yo por mi parte espero sacar adelante esto y poder desarrollar una clase que almacene todo este know how
Un abrazo y agradezo cualquier ayuda
David Lagos S.
Coquimbo-Chile
www.wificafe.cl
webmaster@wificafe.cl
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
DLL32 function
Posted: Tue Apr 01, 2008 07:53 AM

David,

El lenguaje C es realmente simple. De ah铆 radica su potencia y su belleza.

Fu茅 dise帽ado para programar el sistema operativo Unix (padre de Linux, Mac, etc.), y se convirti贸 de "facto" en el lenguaje ideal para desarrollar los sistemas operativos. Por ejemplo, decidimos usar el lenguaje C para construir Harbour, para as铆 obtener la m谩xima potencia y tener un control total :-)

Hace exactamente lo que se le dice. Si se le dice algo mal, 茅l lo hace mal. Es decir, no hace cosas por "su cuenta". Es un robot que nos obedece en todo. Y por otra parte est谩 tan cercano a la m谩quina, que en realidad es "generar" ensamblador, usando un lenguaje y "l贸gica" a nivel humano.

Haz todas las preguntas que quieras aqui, que con mucho gusto te ayudaremos a que te "enamores" de 茅l :-) y de paso le servir谩 a m谩s compa帽eros.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 86
Joined: Sat Jun 24, 2006 04:27 PM
DLL32 function
Posted: Tue Apr 01, 2008 03:17 PM

Buen d铆a para todos...

Que tal David y Antonio, disculpen que les realice esta pregunta la cual no est谩 directamente asociada a la prengunta inicial, pero la cual creo que nos va a beneficiar a todos.

Al igual que David estoy incursionando en lenguaje C, y aunque tengo muy poca experiencia porque en la universidad vi lenguaje C versi贸n 1.0, pero fue hace mucho tiempo y no recuerdo mucho.

La pregunta es: Antonio ya que debemos aprender lenguaje C para aplicarlo a [x]Harbour que versi贸n nos recomiendas o se aplica a [x]Harbour?, porque existen muchas versiones de C (C, C++, C#, Visual C, etc.) y como debemos aprender y para no perder mucho tiempo, nos enfocariamos solo en aprender la versi贸n que necesitamos. De antemano muchas gracias

Saludos,

Antonio Castro
Maracaibo - Venezuela
ant_cas@yahoo.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
DLL32 function
Posted: Tue Apr 01, 2008 06:18 PM

Lenguaje C solamente. Ni C++, ni C#, ni Visual C.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 113
Joined: Wed Jan 10, 2007 08:43 PM
DLL32 function
Posted: Tue Apr 01, 2008 07:08 PM

Antonio:
Mil gracias por tus respuestas. Si no me equivoco C++ es simplemente C con soporte de Clases, correcto?
Si es as铆, me debiera servir el libro "Teach Yourselve Borland C++ in 14 days"?. Obviamente sin aplicar la parte de objetos y ya que utilizo borland c++ 5.51 como compilador.
Nuevamente mil gracias por tu ayuda desinteresada.
Saludos

David Lagos S.
Coquimbo-Chile
www.wificafe.cl
webmaster@wificafe.cl