DLL32 Question!!!

DLL32 Question!!!

Postby metaldrummer » Mon Mar 31, 2008 6:35 pm

Hello everybody:
I have the following code:

Code: Select all  Expand view
#include "hbclass.ch"
#include "fivewin.ch"

#define PRINTER_ENUM_DEFAULT     1
#define PRINTER_ENUM_LOCAL       2
#define PRINTER_ENUM_CONNECTIONS 4
#define PRINTER_ENUM_FAVORITE    4
#define PRINTER_ENUM_NAME        8
#define PRINTER_ENUM_REMOTE      10
#define PRINTER_ENUM_SHARED      20
#define PRINTER_ENUM_NETWORK     40

FUNCTION Main()
   LOCAL aPrinters, nNecesitados, nRetornados

   TotPrinters(PRINTER_ENUM_NAME,NIL,1,@aPrinters,0,@nNecesitados,@nRetornados)
   MsgInfo( aPrinters)
   MsgInfo( nNecesitados)
   MsgInfo( nRetornados)
   Msginfo( Len(aPrinters), "Impresoras Encontradas")
   MsgInfo( WinDefaultPrinter(), "Impresora por Defecto")
   FOR n := 1 TO Len(aPrinters)
      MsgInfo(aPrinters[n])
   NEXT

RETURN NIL

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


Unfortunately I was unable to get printers installed on my system via the DLL32 and if through a # pragma BEGINDUMP .... ENDDUMP using an assigned code on the Internet.
My need is that I have no idea of C++ and require begin development of an application for a center for Internet and the first thing I have to learn is to control printers when they receive work.
Variable aPrinters always returns NIL like the others.
Perhaps I can guide without having to use # pragma would appreciate it. I have used the SDK reference windows.
Many thanks in advance
[b]David Lagos S.
Coquimbo-Chile
www.wificafe.cl
webmaster@wificafe.cl[/b]
User avatar
metaldrummer
 
Posts: 113
Joined: Wed Jan 10, 2007 8:43 pm
Location: Coquimbo-Chile

Postby Antonio Linares » Mon Mar 31, 2008 8:39 pm

David,

Windows API EnumPrinters() function is quite complex to be properly managed using the PRG command DLL FUNCTION.

The C code that you have published in the Spanish forums, is it working for you ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41394
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby metaldrummer » Mon Mar 31, 2008 9:49 pm

Antonio Linares wrote:David,

Windows API EnumPrinters() function is quite complex to be properly managed using the PRG command DLL FUNCTION.

The C code that you have published in the Spanish forums, is it working for you ?


View post in:
http://fivetechsoft.com/forums/viewtopi ... 1372#51372
Regards
[b]David Lagos S.
Coquimbo-Chile
www.wificafe.cl
webmaster@wificafe.cl[/b]
User avatar
metaldrummer
 
Posts: 113
Joined: Wed Jan 10, 2007 8:43 pm
Location: Coquimbo-Chile

Postby Antonio Linares » Mon Mar 31, 2008 10:19 pm

David,

I have answered you in the spanish forums,
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41394
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby StefanHaupt » Tue Apr 01, 2008 7:18 am

Hello David,

here is the function you need, I hope it works

Code: Select all  Expand view
#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) ;
}

HB_FUNC( PRINTFILERAW )  {
  UCHAR  printBuffer[BIG_BUFFER], *cPrinterName, *cFileName, *cDocName ;
  HANDLE  hPrinter, hFile ;
  DOC_INFO_1 DocInfo ;
  DWORD nRead, nWritten, rVal = -1 ;
  if (ISCHAR(1) && ISCHAR(2)) {
    cPrinterName= hb_parc(1) ;
    cFileName= hb_parc(2) ;
    if ( OpenPrinter(cPrinterName, &hPrinter, NULL) != 0 ) {
      DocInfo.pDocName = hb_parc(3) ;
      DocInfo.pOutputFile = NULL ;
      DocInfo.pDatatype = "RAW" ;
      if ( StartDocPrinter(hPrinter,1,(char *) &DocInfo) != 0 ) {
        if ( StartPagePrinter(hPrinter) != 0 ) {
          hFile = CreateFile(cFileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL)   ;
          if (hFile != INVALID_HANDLE_VALUE ) {
            while (ReadFile(hFile, printBuffer, BIG_BUFFER, &nRead, NULL) && (nRead > 0)) {
              if (printBuffer[nRead-1] == 26 )
                nRead-- ; // Skip the EOF() character
              WritePrinter(hPrinter, printBuffer, nRead, &nWritten) ;
            }
            rVal = 1 ;
            CloseHandle(hFile) ;
          }
          else
            rVal= -6 ;
          EndPagePrinter(hPrinter) ;  // 28/11/2001 10:16
        }
        else
          rVal = -4 ;
        EndDocPrinter(hPrinter);
      }
      else
        rVal= -3 ;
      ClosePrinter(hPrinter) ;
    }
    else
      rVal= -2 ;
  }
  hb_retnl(rVal) ;
}

#pragma ENDDUMP
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 36 guests