|
分類:[VB.NET/VB2005 以降]
OpenPrinterを使ってもプリンタのハンドルが取得できません。
なぜでしょうか?
下記のように書いてあります。
Public Const SERVER_ACCESS_ADMINISTER As Integer = 1
Public Structure PRINTER_DEFAULTS
Public pDatatype As IntPtr
Public pDevMode As IntPtr
Public DesiredAccess As Integer
End Structure
<DllImport("winspool.drv", EntryPoint:="OpenPrinterA", ExactSpelling:=True, _
SetLastError:=True, CallingConvention:=CallingConvention.StdCall, _
CharSet:=CharSet.Ansi)> _
Public Function OpenPrinter( _
<InAttribute()> ByVal pPrinterName As String, _
<OutAttribute()> ByRef hPrinter As IntPtr, _
<InAttribute()> ByRef pDefault As PRINTER_DEFAULTS) As Boolean
End Function
Dim Status As Boolean
Dim PrinterName As String = "RICOH imagio MP C4500 RPCS"
Dim hPrinter As IntPtr
Dim pDefault As PRINTER_DEFAULTS
pDefault.pDatatype = IntPtr.Zero
pDefault.pDevMode = IntPtr.Zero
pDefault.DesiredAccess = SERVER_ACCESS_ADMINISTER
Status = OpenPrinter(PrinterName, hPrinter, pDefault)
|