Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Public Class Form1
Structure TDBFh
<VBFixedArray(4), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=4)> Dim lupdt() As Byte
Dim Rcount As Integer
Dim hsize As Integer
Dim recnm As Integer
Dim fHdl As Integer
<VBFixedArray(260), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=260)> Dim Temp() As Byte
Public Sub Initialize()
ReDim lupdt(4)
ReDim Temp(260)
End Sub
End Structure
Declare Function GetThdllVersion Lib "Hamlog50.dll" () As Integer
Declare Function dbf_open Lib "Hamlog50.dll" (ByVal s As String, ByRef d As TDBFh) As Integer
Declare Sub dbf_close Lib "Hamlog50.dll" (ByRef d As TDBFh)
Declare Function dbf_rcount Lib "Hamlog50.dll" (ByRef d As TDBFh) As Integer
Declare Function dbf_read Lib "Hamlog50.dll" (ByRef d As TDBFh, ByVal n As Integer, ByVal s As String) As Integer
Declare Sub GetDxEntity Lib "Hamlog50.dll" (ByVal calls As String, ByVal buff As String)
Public Th As TDBFh
Private Structure COPYDATASTRUCT
Public dwData As IntPtr
Public cbData As Integer
Public lpData As IntPtr
End Structure
Dim cmmd As Int32
Dim Hwnd1 As Int32
Dim Hwnd2 As Int32
Dim cbuff As String
Dim cds As COPYDATASTRUCT
Private Const WM_COPYDATA As Integer = &H4A
<DllImport("user32.dll")> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll")> _
Private Shared Function SendMessage _
(ByVal hWnd As IntPtr, ByVal Msg As Integer, _
ByVal wParam As IntPtr, ByRef lParam As COPYDATASTRUCT) As IntPtr
End Function
<DllImport("user32.dll")> _
Private Shared Function SetForegroundWindow(ByVal wnd As Integer) As IntPtr
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Hwnd1 = FindWindow("TThwin", vbNullString)
If Hwnd1 < 1 Then ' ハムログが起動していない
Label5.Text = "ハムログが起動していない"
Button1.Enabled = False
Else
Button1.Enabled = True
End If
Label6.Text = "C:\Hamlog\VbNet\Hamlog.hdb"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'THW からの転送
Hwnd1 = FindWindow("TThwin", vbNullString)
If Hwnd1 < 1 Then ' ハムログが起動していない
Exit Sub
End If
cmmd = 115
cds.dwData = cmmd
cbuff = vbNullString
cds.cbData = 0
Hwnd2 = SendMessage(Hwnd1, WM_COPYDATA, Me.Handle, cds)
If Not Hwnd2.Equals(IntPtr.Zero) Then
SetForegroundWindow(Hwnd2)
End If
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_COPYDATA Then
Dim cds As COPYDATASTRUCT
cds = CType(Marshal.PtrToStructure(m.LParam, GetType(COPYDATASTRUCT)), COPYDATASTRUCT)
TextBox1.Text = Marshal.PtrToStringAnsi(cds.lpData)
Else
MyBase.WndProc(m)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'テキストファイルを上書きで保存する
Dim f_name As String
f_name = "C:\vb_net_test.txt"
Dim sw As New System.IO.StreamWriter(f_name, False, _
System.Text.Encoding.Default)
'書込み
sw.Write(TextBox1.Text)
sw.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button3.Click
'テキストファイルを1行づつ読み込む
TextBox1.Clear()
Dim sr As New System.IO.StreamReader("C:\LOGLIST_2.csv", System.Text.Encoding.Default)
'読込むテキストファイルのバッファを確保
Dim sb As New System.Text.StringBuilder( _
CInt(New System.IO.FileInfo("C:\LOGLIST_2.csv").Length))
'ファイルの最後までループ
Do Until sr.Peek = -1
'1行づつ読込む(文字列の連結が高速に処理される)
sb.Append(sr.ReadLine & vbCrLf)
Loop
sr.Close()
'読込んだデータをテキストボックスに表示
TextBox1.Text = sb.ToString()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'レコード件数取得
Dim ver As Integer
Dim sd As Integer
Dim recno As Integer
ver = GetThdllVersion()
Label1.Text = ver
sd = dbf_open("C:\Hamlog\VbNet\Hamlog.hdb", Th) 'レコード数取得のためデータベースをオープン
recno = dbf_rcount(Th) 'レコード数取得
dbf_close(Th) 'データベースクローズ
Label2.Text = recno
End Sub
End Class