473,320 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to use Getprinter in vb.net ?

Zok
hello all,
I am trying for a long time now to get the information of a printer.
i have such cide in vb6 but having troubles moving it into vb.net.
can anyone please provide me with the correct vb.net declaration (there

are so many different versions online) and example of how to use these
apis :
openprinter
getprinter
setprinter
and example of how to use
this is the code im working on now, but getprinter just doesnt work.
Private Declare Function OpenPrinter Lib "winspool.drv" Alias
"OpenPrinterA" (ByVal pPrinterName As String, ByRef phPrn As Integer,
ByRef pDefault As Integer) As Integer
Declare Function GetPrinter Lib "winspool.drv" Alias "GetPrinterA"
(ByVal hPrinter As Integer, ByVal Level As Integer, ByRef pPrinter As
Object, ByVal cbBuf As Integer, ByRef pcbNeeded As Integer) As Integer
Dim hPrn As Integer
Dim Buffer() As Byte
Dim BytesNeeded As Integer
Dim BytesUsed As Integer
Call OpenPrinter(m_DevName, hPrn, 0)
If hPrn Then
Call GetPrinter(hPrn, 2, 0, 0, BytesNeeded)
If Err.LastDllError = ERROR_INSUFFICIENT_BUFFER Then
ReDim Buffer(BytesNeeded - 1)
nRet = GetPrinter(hPrn, 2, Buffer(0), BytesNeeded,
BytesUsed)
end if
Dec 15 '05 #1
1 4552
Download the ApiGuide from www.allapi.net. That program have samples of most
WinAPIs, and some samples for .Net. If no .Net sample is available, it shows
the class that replaced the API function.

[]s
Cesar

"Zok" <zo*****@hotmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
hello all,
I am trying for a long time now to get the information of a printer.
i have such cide in vb6 but having troubles moving it into vb.net.
can anyone please provide me with the correct vb.net declaration (there

are so many different versions online) and example of how to use these
apis :
openprinter
getprinter
setprinter
and example of how to use
this is the code im working on now, but getprinter just doesnt work.
Private Declare Function OpenPrinter Lib "winspool.drv" Alias
"OpenPrinterA" (ByVal pPrinterName As String, ByRef phPrn As Integer,
ByRef pDefault As Integer) As Integer
Declare Function GetPrinter Lib "winspool.drv" Alias "GetPrinterA"
(ByVal hPrinter As Integer, ByVal Level As Integer, ByRef pPrinter As
Object, ByVal cbBuf As Integer, ByRef pcbNeeded As Integer) As Integer
Dim hPrn As Integer
Dim Buffer() As Byte
Dim BytesNeeded As Integer
Dim BytesUsed As Integer
Call OpenPrinter(m_DevName, hPrn, 0)
If hPrn Then
Call GetPrinter(hPrn, 2, 0, 0, BytesNeeded)
If Err.LastDllError = ERROR_INSUFFICIENT_BUFFER Then
ReDim Buffer(BytesNeeded - 1)
nRet = GetPrinter(hPrn, 2, Buffer(0), BytesNeeded,
BytesUsed)
end if
.
.
.
Call ClosePrinter(hPrn)
how to make this work ?
Thanks in advanced.

Dec 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gordon Truslove | last post by:
I've been trying to get the printer status using GetPrinter and Printer_Info_2 I'm getting closer, but it still fails. Error 122 - The data area passed to a system call is too small....
7
by: Just Me | last post by:
I know (or at least think) the following is not correct. The comment says what I want to do, but I think the code will copy the data not the address. Is this one of the things that can't be...
1
by: Zok | last post by:
hello all, I am trying for a long time now to get the information of a printer. i have such cide in vb6 but having troubles moving it into vb.net. can anyone please provide me with the...
7
by: creative1 | last post by:
Hi everyone I am facing a strange problem in the exe file of my project. i.e I created setup for software instllation. I tried it on my PC and works fine. However, when my supervisor run it on...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.