Type DNGINFO
	LPT_Nr As Integer
	LPT_Adr As Integer
	DNG_Cnt As Integer
End Type

Declare Function Init_MatrixAPI Lib "matrix32.dll" () As Integer
Declare Function Release_MatrixAPI Lib "matrix32.dll" () As Integer
Declare Function PausePrinterActivity Lib "matrix32.dll" () As Integer
Declare Function ResumePrinterActivity Lib "matrix32.dll" () As Integer
Declare Function GetPortAdr Lib "matrix32.dll" (ByVal DNG_LPT As Integer) As Integer
Declare Function GetVersionAPI Lib "matrix32.dll" () As Long
Declare Function GetVersionDRV Lib "matrix32.dll" () As Long
Declare Function GetVersionDRV_USB Lib "matrix32.dll" () As Long
Declare Function Dongle_Find Lib "matrix32.dll" () As Integer
Declare Function Dongle_FindEx Lib "matrix32.dll" (ByRef xBuffer As DNGINFO) As Long
Declare Function Dongle_Count Lib "matrix32.dll" (ByVal DNG_LPT As Integer) As Integer
Declare Function Dongle_Version Lib "matrix32.dll" (ByVal DNG_Nr As Integer, ByVal DNG_LPT As Integer) As Long 
Declare Function Dongle_Model Lib "matrix32.dll" (ByVal DNG_Nr As Integer, ByVal DNG_LPT As Integer) As Integer
Declare Function Dongle_MemSize Lib "matrix32.dll" (ByVal DNG_Nr As Integer, ByVal DNG_LPT As Integer) As Integer
Declare Function Dongle_ReadData Lib "matrix32.dll" (ByVal UserCode As Long, ByRef DataIn As Long, ByVal MaxVar As Integer, ByVal DNG_Nr As Integer, ByVal DNG_LPT As Integer) As Integer
Declare Function Dongle_WriteData Lib "matrix32.dll" (ByVal UserCode As Long, ByRef DataOut As Long, ByVal MaxVar As Integer, ByVal DNG_Nr As Integer, ByVal DNG_LPT As Integer) As Integer


Dim RetCode As Integer
Dim xBuffer As DNGINFO
Dim DataIn(256) As Long
Dim DataOut(256) As Long
Dim DNG_Version As Long
Dim DNG_LPT As Integer
Dim DNG_LPTADR As Integer
Dim DNG_Nr As Integer
Dim DNG_Count As Integer
Dim DNG_Mem As Integer
Dim DNG_MaxVar As Integer
Dim DataBlock(2) As Long
Dim VerMajor As Integer
Dim VerMinor As Integer
Const Shift16 = 2 ^ 16

'***********************************************************
'* LPT1 ポートの確認 *
'***********************************************************
DNG_LPT = 1
DNG_LPTADR = GetPortAdr(DNG_LPT)
If DNG_LPTADR = 0 Then
	MsgBox "LPT1が存在しません"
End If
MsgBox "LPT1のアドレス: " & Hex(DNG_LPTADR)

'***********************************************************
'* LPT1に接続されたMatrix数を確認 *
'***********************************************************
DNG_Count = Dongle_Count(DNG_LPT)
If DNG_Count = 0 Then
	MsgBox "LPT" & DNG_LPT & " にはMatrixは接続されていません"
End If
MsgBox "検出結果: " & DNG_Count & " 個のMatrixがLPTポート" & DNG_LPT & “に見つかりました”
DNG_Nr = DNG_Count

'***********************************************************
'* LPT1最後のMatrixのメモリサイズを読み込み *
'* データフィールド数を計算 *
'***********************************************************
DNG_Mem = Dongle_MemSize(DNG_Nr, DNG_LPT)
If DNG_Mem = 0 Then
	MsgBox "Matrixメモリサイズ取得中にエラー発生"
End If
DNG_MaxVar = DNG_Mem / 4
MsgBox "データフィールド数: " & DNG_MaxVar

'***********************************************************
'* LPT1最後のMatrixのバージョンを取得 *
'***********************************************************
DNG_Version = Dongle_Version(DNG_Nr, DNG_LPT)
If DNG_Version = 0 Then
	MsgBox "Matrixのバージョン読み取り中にエラー発生"
Else
	VerMinor = CInt(DNG_Version And 65535)
	VerMajor = CInt(DNG_Version \ Shift16)
	MsgBox "このMatrixのバージョン: " & VerMajor &
	"." VerMinor
End If

'***********************************************************
'* LPT1最後のMatrix の 15個のデータフィールドから *
'* ユーザコード 1234 でデータを読み取り、表示する *
'***********************************************************
RetCode = Dongle_ReadData(1234, DataIn(0), 15, DNG_Nr, DNG_LPT)
If RetCode < 0 Then
	MsgBox "Matrixからデータ読み取り中にエラー発生"
End If
For i = 0 To 14
	MsgBox "データフィールド no. " & i + 1 & "の値: " & DataIn(i)
Next i

'***********************************************************
'* LPT1最後のMatrix の 15個のデータフィールドにユーザコード 1234を使って *
'* 値 101,102...115 を書き込む *
'***********************************************************
For i = 0 To 14
	DataOut(i) = 101 + i
Next i
RetCode = Dongle_WriteData(1234, DataOut(0), 15, DNG_Nr, DNG_LPT)
If RetCode < 0 Then
	MsgBox "Matrixに書き込み中にエラー発生"
End If
MsgBox "書き込みに成功しました"