#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
JmGarcia wrote:En el fichero DLL.CH esta parte de lo que buscas:
- Code: Select all Expand view RUN
#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
- Code: Select all Expand view RUN
#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 ENDDUMP
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"
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"
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 ?
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 ?
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: Google [Bot] and 37 guests