473,385 Members | 1,523 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,385 software developers and data experts.

GetPrinterData


Hi,

I have some problems to use GetPrinterData Win32 API. I can't get the result
of this API when the ValueName is a REG_SZ or a MULTI_REG_SZ.

Can anybody help me ?

Thanks,

Delfim.

this a part of my code :

<DllImport("winspool.Drv", CharSet:=CharSet.Ansi,
EntryPoint:="GetPrinterDataA", _
SetLastError:=True, ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Private Shared Function GetPrinterData( _
ByVal hPrinter As IntPtr, _
<MarshalAs(UnmanagedType.LPStr)> ByVal pValueName As String, _
ByRef pType As Integer, _
ByRef pData As IntPtr, _
ByVal nSize As Integer, _
ByRef pcbNeeded As Integer) As Integer
End Function

Public Function GetPrinterData(ByVal PrinterName As String, ByVal ValueName
As String) As Object
Dim hPrinter As IntPtr
Dim pData As IntPtr = IntPtr.Zero
Dim cBuf As Integer
Dim pcbNeeded As Integer
Dim pType As Integer
Dim ret As Integer
Dim oData As Object

hPrinter = OpenPrinter(PrinterName)
ret = GetPrinterData(hPrinter, ValueName, pType, IntPtr.Zero, 0,
pcbNeeded)
If pcbNeeded <= 0 Then
Throw (New System.Exception("Unable to allocate memory"))
End If

pData = Marshal.AllocHGlobal(pcbNeeded)
ret = GetPrinterData(hPrinter, ValueName, pType, pData, pcbNeeded, cBuf)
If ret <> 0 Then
Throw New Win32Exception(Marshal.GetLastWin32Error())
End If

Select Case pType
Case REG_DWORD
oData = pData.ToInt32

Case REG_SZ
oData = pData 'Marshal.PtrToStringAuto(pData)

Case Else
oData = pData
End Select

ClosePrinter(hPrinter)

Return oData
End Function
Feb 24 '06 #1
0 1446

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

Similar topics

3
by: Delfim Da Costa | last post by:
Hi, I have some problems to use GetPrinterData Win32 API. in fact my problem is : how can get the in a string a buffer known by it's ptr ? Can anybody help me ? Thanks, Delfim.
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.