473,396 Members | 1,826 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,396 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 2472
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

4
by: Umesh | last post by:
Hi all I am trying to change the printer(like paper source ,etc) setting in C#. But i am unable to do it. I am not sure how to do it. should i have to use WIN API like Openprinter , getprinter ,...
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....
6
by: Stephan Perschke | last post by:
Hi, I try to change some printer settings using the win32 api OpenPrinter, GetPrinter and SetPrinter. I copied most of the code from this or related newsgroups. However, OpenPrinter, GetPrinter...
10
by: Joe M | last post by:
I was wondering if someone could lend me a hand with a C# problem I am having I am trying to use the “setPrinter” api to change the duplex setting (under printing preferences on printer...
0
by: Francisco Araujo | last post by:
I have been trying to change printer settings thru SetPrinter API and it works successfully for local printers, but with network printers i don't get neither an error message or anything else. ...
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...
9
by: id10t error | last post by:
Hello, I am going to be using a Symbol WT4090 to scan items. I need to printer a tag from the Zebra ql320 plus. I am trying to do this is Visual basic 2005. Does anyone know and good site to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

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.