プリンタのドライバを列挙 <TOP>
EnumPrinterDrivers
プリンタのドライバを列挙
MoveMemory
メモリの指定領域をコピー
lstrcpy 文字列をコピーする
'================================================================ '= プリンタのドライバを列挙 '= (EnumPrinterDrivers.bas) '================================================================ #include "Windows.bi" Type DRIVER_INFO_1 pName As Long End Type ' プリンタのドライバを列挙 Declare Function Api_EnumPrinterDrivers& Lib "winspool.drv" Alias "EnumPrinterDriversA" (ByVal pName$, ByVal pEnvironment$, ByVal Level&, pDriverInfo As Any, ByVal cdBuf&, pcbNeeded&, pcRetruned&) ' メモリの指定領域をコピー Declare Sub MoveMemory Lib "Kernel32" Alias "RtlMoveMemory" (Dest As Any, Source As Any, ByVal Length&) ' 文字列をコピーする Declare Function Api_lstrcpy& Lib "Kernel32" Alias "lstrcpy" (lpszString1 As Any, lpszString2 As Any) Var Shared List1 As Object Var Shared Button1 as Object List1.Attach GetDlgItem("List1") : List1.SetFontSize 14 Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14 '================================================================ '= '================================================================ Declare Sub Button1_on edecl () Sub Button1_on() Var Level As Long Var Needed As Long Var Returned As Long Var Count As Long Var DriverName As String * 128 Var Ret As Long List1.Resetcontent '構造体のレベルを指定 Level = 1 'バッファに必要なサイズを取得 Ret = Api_EnumPrinterDrivers(ByVal 0, ByVal 0, Level, ByVal 0, 0, Needed, Returned) 'ドライバが取得できないとき If Needed <= 0 Then List1.AddString "取得できません!" Exit Sub End If 'バッファを確保 Var bytDriverInfo1Buffer(Needed - 1) As Byte 'ドライバ情報を取得 Ret = Api_EnumPrinterDrivers(ByVal 0, ByVal 0, Level, bytDriverInfo1Buffer(0), Needed, Needed, Returned) '取得したドライバ情報の構造体を確保 Var udtDriverInfo1(Returned - 1) As DRIVER_INFO_1 '取得したドライバ情報を構造体へ移動 MoveMemory udtDriverInfo1(0), bytDriverInfo1Buffer(0), Len(udtDriverInfo1(0)) * Returned 'バッファにドライバ情報がある間は For Count = 0 To Returned - 1 'ドライバ名を複写 Ret = Api_lstrcpy(DriverName, ByVal udtDriverInfo1(Count).pName) 'ドライバ名を表示 List1.AddString Left$(DriverName, InStr(DriverName, Chr$(0)) - 1) Next Count End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End