tagCANDY CGI VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板)
VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板)
[ツリー表示へ]  [ワード検索]  [Home]

タイトル 用紙名を列挙したい
投稿日: 2005/11/04(Fri) 09:40
投稿者VB.NETビギナー
[OSのVer]:WindowsXP    [VBのVer]:VB.NET2003

プリントサーバーに追加した専用用紙の用紙名に対応する用紙番号を取得したいのですが
用紙番号らしきものは取得できたのですが、用紙名を取得する事ができません。
以下のサンプルでは、
LIST1(リストボックス)に用紙サイズ番号
LIST2(リストボックス)に用紙名
をセットしたく試していますが、LIST1は成功、LIST2はMoveMemoryでエラーとなってしまいます。
アドバイスいただければ幸いです。

(以下サンプル)
Private Declare Function DeviceCapabilities Lib "winspool.drv" Alias "Device
CapabilitiesA" _
(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

Private 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 Byte, _
ByVal pDevMode As IntPtr) As Integer

Private Const DC_PAPERS As Short = 2
Private Const DC_PAPERNAMES As Short = 16
    
Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory"
_
(ByVal Destination As String, _
<System.Runtime.InteropServices.OutAttribute()> ByVal Source As Byte, _
ByVal Length As Long)
    
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As
System.EventArgs) Handles MyBase.Load
        
Dim myPrinter As String
Dim mBuf As Integer
Dim mPaperS() As Short
Dim sPaperName As String
Dim AllPaper As Integer

List1.Items.Clear()
List2.Items.Clear()

myPrinter = "FUJITSU XL-6200"

'LIST1 用紙番号の列挙
' バッファに必要なサイズを取得
mBuf = DeviceCapabilities(myPrinter, Nothing, DC_PAPERS, Nothing, System.IntPtr.Zero)
' バッファ確保
ReDim mPaperS(mBuf - 1)
'用紙番号を取得
DeviceCapabilities(myPrinter, Nothing, DC_PAPERS, mPaperS, System.IntPtr.Zero)
'用紙番号を列挙
With List1
For AllPaper = 0 To mBuf - 1
    ' 用紙名番号
    .Items.Add(AllPaper + 1 & ":" & mPaperS(AllPaper))
Next AllPaper
End With

'LIST2 用紙名の列挙
' バッファに必要なサイズを取得
mBuf = DeviceCapabilities(myPrinter, Nothing, DC_PAPERS, Nothing, System.IntPtr.Zero)
' バッファ確保
Dim mPaper(64, mBuf - 1) As Byte
'用紙名を取得
DeviceCapabilitiesName(myPrinter, Nothing, DC_PAPERNAMES, mPaper, System.IntPtr.Zero)

'用紙名を列挙
With List2
For AllPaper = 0 To mBuf - 1
  '下の MoveMemory が上手くできません。
  MoveMemory(sPaperName, mPaper(0, AllPaper), 64)
  ' 用紙名追加
  .Items.Add(AllPaper + 1 & ":" & sPaperName)
Next AllPaper
End With
        
End Sub
  

- 関連一覧ツリー をクリックするとツリー全体を一括表示します)

古いスレッドにレスはつけられません。