タイトル | : プリンタ情報について |
記事No | : 4874 |
投稿日 | : 2007/01/22(Mon) 18:01 |
投稿者 | : てつ |
初めて投稿します。
APIのDeviceCapabilitiesを使い プリンタの情報を取得したいと考えています。
用紙サイズ番号は取得できるのですが 用紙サイズ名が取得できません。
どなたか取得方法を知っていましたら教えてください。
Public Const DC_PAPERS = 2 Public Const DC_BINS = 6 Public Const DC_BINNAMES = 12 Public Const DC_PAPERNAMES = 16
Declare Function DeviceCapabilities Lib "winspool.drv" Alias "DeviceCapabilitiesA" ( _ ByVal pDevice As String, _ ByVal pPort As String, _ ByVal fwCapability As Short, _ <System.Runtime.InteropServices.OutAttribute()> ByVal pOutput() As Short, _ ByVal pDevMode As IntPtr) As Integer
Declare Function DeviceCapabilitiesName Lib "winspool.drv" Alias "DeviceCapabilitiesA" ( _ ByVal pDevice As String, _ ByVal pPort As String, _ ByVal fwCapability As Short, _ <System.Runtime.InteropServices.OutAttribute()> ByVal pOutput() As String, _ ByVal pDevMode As IntPtr) As Integer
' ある位置から別の位置にメモリブロックを移動する関数の宣言 Public Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" _ (ByVal Destination As String, _ <System.Runtime.InteropServices.OutAttribute()> ByVal Source As Byte, _ ByVal Length As Long)
Public Function GetPaperIndex(ByVal strPrinterName As String, ByVal strPaperName As String) As Integer
Dim lngIdx As Long Dim lngBinsCount As Long Dim strBuf() As String Dim x As String Dim intBins() As Short Dim strBinName As String Dim lngInitPos As Long Dim strRowSource As String
strRowSource = "" lngInitPos = -1 lngBinsCount = DeviceCapabilities(strPrinterName, Nothing, _ DC_PAPERS, Nothing, _ System.IntPtr.Zero)
Try
If lngBinsCount >= 1 Then ReDim intBins(lngBinsCount - 1) ReDim strBuf(lngBinsCount - 1) '用紙サイズ番号取得 Call DeviceCapabilities(strPrinterName, Nothing, _ DC_PAPERS, intBins, _ System.IntPtr.Zero) '用紙サイズ名取得 エラーになる Call DeviceCapabilities(strPrinterName, Nothing, _ DC_PAPERNAMES , intBins, _ System.IntPtr.Zero)
For lngIdx = 0 To lngBinsCount - 1 '用紙サイズ番号が取れているか確認 MsgBox(intBins(lngIdx)) Next lngIdx End If
Catch ex As Exception MsgBox(ex.Message)
End Try
End Function
|