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.
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,
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
#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
#endifJmGarcia 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
#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"#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 ENDDUMPmetaldrummer 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"
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.
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"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 ?
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 ?
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 ?
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 ?
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.
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
Lenguaje C solamente. Ni C++, ni C#, ni Visual C.
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