BarryTang
asked on
How to use DLL in my VB program ?
For the present, I would like to write a VB program that
read the content of a midi ( .mid ) file by using the
reading function in a external DLL.
Since I have not familiar to write program that call
functions in external DLL file, would someone give me some guildline/reference code to initialize this program.
You can refer to the DLL that located in the following
web site:
http://www.borg.com/~jglatt/progs/software.htm
The DLL is midifile.dll and the function I need to use should be MidiReadFile()
Thank you for your help
read the content of a midi ( .mid ) file by using the
reading function in a external DLL.
Since I have not familiar to write program that call
functions in external DLL file, would someone give me some guildline/reference code to initialize this program.
You can refer to the DLL that located in the following
web site:
http://www.borg.com/~jglatt/progs/software.htm
The DLL is midifile.dll and the function I need to use should be MidiReadFile()
Thank you for your help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In VB either multimedia file or data file the storage and retrival of file attributes procedure is same.You can use standard file handling controls to do what you want.If your particular about Using DLL for this you can try with the standard file handling DLLs.I am furnishing an example below.cut it and modify to your needs.
'Create a form with a command button (command1), a list box (list1)
'and four text boxes (text1, text2, text3 and text4).
'Type in the first textbox a startingpath like c:\
'and in the second textbox you put a pattern like *.* or *.txt
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Const MAX_PATH = 260
Const MAXDWORD = &HFFFF
Const INVALID_HANDLE_VALUE = -1
Const FILE_ATTRIBUTE_ARCHIVE = &H20
Const FILE_ATTRIBUTE_DIRECTORY = &H10
Const FILE_ATTRIBUTE_HIDDEN = &H2
Const FILE_ATTRIBUTE_NORMAL = &H80
Const FILE_ATTRIBUTE_READONLY = &H1
Const FILE_ATTRIBUTE_SYSTEM = &H4
Const FILE_ATTRIBUTE_TEMPORARY = &H100
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Function StripNulls(OriginalStr As String) As String
If (InStr(OriginalStr, Chr(0)) > 0) Then
OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
End If
StripNulls = OriginalStr
End Function
Function FindFilesAPI(path As String, SearchStr As String, FileCount As Integer, DirCount As Integer)
'KPD-Team 1999
'E-Mail: KPDTeam@Allapi.net
'URL: http://www.allapi.net/
Dim FileName As String ' Walking filename variable...
Dim DirName As String ' SubDirectory Name
Dim dirNames() As String ' Buffer for directory name entries
Dim nDir As Integer ' Number of directories in this path
Dim i As Integer ' For-loop counter...
Dim hSearch As Long ' Search Handle
Dim WFD As WIN32_FIND_DATA
Dim Cont As Integer
If Right(path, 1) <> "\" Then path = path & "\"
' Search for subdirectories.
nDir = 0
ReDim dirNames(nDir)
Cont = True
hSearch = FindFirstFile(path & "*", WFD)
If hSearch <> INVALID_HANDLE_VALUE Then
Do While Cont
DirName = StripNulls(WFD.cFileName)
' Ignore the current and encompassing directories.
If (DirName <> ".") And (DirName <> "..") Then
' Check for directory with bitwise comparison.
If GetFileAttributes(path & DirName) And FILE_ATTRIBUTE_DIRECTORY Then
dirNames(nDir) = DirName
DirCount = DirCount + 1
nDir = nDir + 1
ReDim Preserve dirNames(nDir)
End If
End If
Cont = FindNextFile(hSearch, WFD) 'Get next subdirectory.
Loop
Cont = FindClose(hSearch)
End If
' Walk through this directory and sum file sizes.
hSearch = FindFirstFile(path & SearchStr, WFD)
Cont = True
If hSearch <> INVALID_HANDLE_VALUE Then
While Cont
FileName = StripNulls(WFD.cFileName)
If (FileName <> ".") And (FileName <> "..") Then
FindFilesAPI = FindFilesAPI + (WFD.nFileSizeHigh * MAXDWORD) + WFD.nFileSizeLow
FileCount = FileCount + 1
List1.AddItem path & FileName
End If
Cont = FindNextFile(hSearch, WFD) ' Get next file
Wend
Cont = FindClose(hSearch)
End If
' If there are sub-directories...
If nDir > 0 Then
' Recursively walk into them...
For i = 0 To nDir - 1
FindFilesAPI = FindFilesAPI + FindFilesAPI(path & dirNames(i) & "\", SearchStr, FileCount, DirCount)
Next i
End If
End Function
Sub Command1_Click()
Dim SearchPath As String, FindStr As String
Dim FileSize As Long
Dim NumFiles As Integer, NumDirs As Integer
Screen.MousePointer = vbHourglass
List1.Clear
SearchPath = Text1.Text
FindStr = Text2.Text
FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
Text3.Text = NumFiles & " Files found in " & NumDirs + 1 & " Directories"
Text4.Text = "Size of files found under " & SearchPath & " = " & Format(FileSize, "#,###,###,##0") & " Bytes"
Screen.MousePointer = vbDefault
End Sub
'Create a form with a command button (command1), a list box (list1)
'and four text boxes (text1, text2, text3 and text4).
'Type in the first textbox a startingpath like c:\
'and in the second textbox you put a pattern like *.* or *.txt
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Const MAX_PATH = 260
Const MAXDWORD = &HFFFF
Const INVALID_HANDLE_VALUE = -1
Const FILE_ATTRIBUTE_ARCHIVE = &H20
Const FILE_ATTRIBUTE_DIRECTORY = &H10
Const FILE_ATTRIBUTE_HIDDEN = &H2
Const FILE_ATTRIBUTE_NORMAL = &H80
Const FILE_ATTRIBUTE_READONLY = &H1
Const FILE_ATTRIBUTE_SYSTEM = &H4
Const FILE_ATTRIBUTE_TEMPORARY = &H100
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Function StripNulls(OriginalStr As String) As String
If (InStr(OriginalStr, Chr(0)) > 0) Then
OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
End If
StripNulls = OriginalStr
End Function
Function FindFilesAPI(path As String, SearchStr As String, FileCount As Integer, DirCount As Integer)
'KPD-Team 1999
'E-Mail: KPDTeam@Allapi.net
'URL: http://www.allapi.net/
Dim FileName As String ' Walking filename variable...
Dim DirName As String ' SubDirectory Name
Dim dirNames() As String ' Buffer for directory name entries
Dim nDir As Integer ' Number of directories in this path
Dim i As Integer ' For-loop counter...
Dim hSearch As Long ' Search Handle
Dim WFD As WIN32_FIND_DATA
Dim Cont As Integer
If Right(path, 1) <> "\" Then path = path & "\"
' Search for subdirectories.
nDir = 0
ReDim dirNames(nDir)
Cont = True
hSearch = FindFirstFile(path & "*", WFD)
If hSearch <> INVALID_HANDLE_VALUE Then
Do While Cont
DirName = StripNulls(WFD.cFileName)
' Ignore the current and encompassing directories.
If (DirName <> ".") And (DirName <> "..") Then
' Check for directory with bitwise comparison.
If GetFileAttributes(path & DirName) And FILE_ATTRIBUTE_DIRECTORY Then
dirNames(nDir) = DirName
DirCount = DirCount + 1
nDir = nDir + 1
ReDim Preserve dirNames(nDir)
End If
End If
Cont = FindNextFile(hSearch, WFD) 'Get next subdirectory.
Loop
Cont = FindClose(hSearch)
End If
' Walk through this directory and sum file sizes.
hSearch = FindFirstFile(path & SearchStr, WFD)
Cont = True
If hSearch <> INVALID_HANDLE_VALUE Then
While Cont
FileName = StripNulls(WFD.cFileName)
If (FileName <> ".") And (FileName <> "..") Then
FindFilesAPI = FindFilesAPI + (WFD.nFileSizeHigh * MAXDWORD) + WFD.nFileSizeLow
FileCount = FileCount + 1
List1.AddItem path & FileName
End If
Cont = FindNextFile(hSearch, WFD) ' Get next file
Wend
Cont = FindClose(hSearch)
End If
' If there are sub-directories...
If nDir > 0 Then
' Recursively walk into them...
For i = 0 To nDir - 1
FindFilesAPI = FindFilesAPI + FindFilesAPI(path & dirNames(i) & "\", SearchStr, FileCount, DirCount)
Next i
End If
End Function
Sub Command1_Click()
Dim SearchPath As String, FindStr As String
Dim FileSize As Long
Dim NumFiles As Integer, NumDirs As Integer
Screen.MousePointer = vbHourglass
List1.Clear
SearchPath = Text1.Text
FindStr = Text2.Text
FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
Text3.Text = NumFiles & " Files found in " & NumDirs + 1 & " Directories"
Text4.Text = "Size of files found under " & SearchPath & " = " & Format(FileSize, "#,###,###,##0") & " Bytes"
Screen.MousePointer = vbDefault
End Sub
BarryTang,
You have 17 opened questions as of this date.
I will be posting in each of these questions.
Please take care of your opened questions older than 30 days by clicking on your logon name link and looking for UnlockedQ or using the links I am providing below.
Please finalize these within 72 hours or I will ask administration to look into your account at that point. If you have questions, please ask and I will provide assistance.
https://www.experts-exchange.com/questions/20187331/Problem-related-to-Unknown-token-received-from-SQL-Server.html
https://www.experts-exchange.com/questions/20133725/Access-Foxpro-2-6-free-tables-from-SQL-server-2000.html
https://www.experts-exchange.com/questions/20088012/Problem-related-to-insert-a-group-of-record-to-a-data-file.html
https://www.experts-exchange.com/questions/20083509/Connection-Failure-using-local-harddisk.html
https://www.experts-exchange.com/questions/20382035/How-can-I-extract-a-music-track-in-a-midi-file-by-DirectMusic-in-VB.html
https://www.experts-exchange.com/questions/20382294/How-can-I-extract-a-music-track-in-a-midi-file-by-DirectMusic-in-VB.html
https://www.experts-exchange.com/questions/20534626/DLL-Function-can-run-in-exe-but-fail-to-run-in-VB6-environment.html
https://www.experts-exchange.com/questions/20521771/How-can-I-avoid-the-split-of-word.html
https://www.experts-exchange.com/questions/20515842/Can-I-use-this-DLL-in-VB6.html
https://www.experts-exchange.com/questions/20513575/Problem-related-to-shell-wait.html
https://www.experts-exchange.com/questions/20493221/Problem-related-to-the-scroll-value.html
https://www.experts-exchange.com/questions/20436510/How-can-I-made-a-form-on-top-but-will-disappear-when-switch-to-screen-of-other-windows-task.html
https://www.experts-exchange.com/questions/20399960/How-to-use-a-C-dll-in-a-VB6-program.html
https://www.experts-exchange.com/questions/20395868/How-to-play-a-specific-frequency-of-wave-sound-out.html
https://www.experts-exchange.com/questions/20375410/How-can-I-display-special-characters-in-VB-controls.html
https://www.experts-exchange.com/questions/20373966/How-to-display-musical-note-from-midi-file-in-a-VB-program.html
https://www.experts-exchange.com/questions/20372811/How-to-use-DLL-in-my-VB-program.html
Thank you.
You have 17 opened questions as of this date.
I will be posting in each of these questions.
Please take care of your opened questions older than 30 days by clicking on your logon name link and looking for UnlockedQ or using the links I am providing below.
Please finalize these within 72 hours or I will ask administration to look into your account at that point. If you have questions, please ask and I will provide assistance.
https://www.experts-exchange.com/questions/20187331/Problem-related-to-Unknown-token-received-from-SQL-Server.html
https://www.experts-exchange.com/questions/20133725/Access-Foxpro-2-6-free-tables-from-SQL-server-2000.html
https://www.experts-exchange.com/questions/20088012/Problem-related-to-insert-a-group-of-record-to-a-data-file.html
https://www.experts-exchange.com/questions/20083509/Connection-Failure-using-local-harddisk.html
https://www.experts-exchange.com/questions/20382035/How-can-I-extract-a-music-track-in-a-midi-file-by-DirectMusic-in-VB.html
https://www.experts-exchange.com/questions/20382294/How-can-I-extract-a-music-track-in-a-midi-file-by-DirectMusic-in-VB.html
https://www.experts-exchange.com/questions/20534626/DLL-Function-can-run-in-exe-but-fail-to-run-in-VB6-environment.html
https://www.experts-exchange.com/questions/20521771/How-can-I-avoid-the-split-of-word.html
https://www.experts-exchange.com/questions/20515842/Can-I-use-this-DLL-in-VB6.html
https://www.experts-exchange.com/questions/20513575/Problem-related-to-shell-wait.html
https://www.experts-exchange.com/questions/20493221/Problem-related-to-the-scroll-value.html
https://www.experts-exchange.com/questions/20436510/How-can-I-made-a-form-on-top-but-will-disappear-when-switch-to-screen-of-other-windows-task.html
https://www.experts-exchange.com/questions/20399960/How-to-use-a-C-dll-in-a-VB6-program.html
https://www.experts-exchange.com/questions/20395868/How-to-play-a-specific-frequency-of-wave-sound-out.html
https://www.experts-exchange.com/questions/20375410/How-can-I-display-special-characters-in-VB-controls.html
https://www.experts-exchange.com/questions/20373966/How-to-display-musical-note-from-midi-file-in-a-VB-program.html
https://www.experts-exchange.com/questions/20372811/How-to-use-DLL-in-my-VB-program.html
Thank you.
Hi BarryTang,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Accept cool12399's comment(s) as an answer.
BarryTang, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept this comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Accept cool12399's comment(s) as an answer.
BarryTang, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept this comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
per recommendation
SpideyMod
Community Support Moderator @Experts Exchange
SpideyMod
Community Support Moderator @Experts Exchange
ASKER
Thanks for reply !
I try to write few VB lines according to what you suggest
in a form as follows :
Private Declare Function MidiReadFile Lib "MidiFile" (ByVal tmid As String) As Long
Private Sub Command1_Click()
Open "test.mid" For Input As #1
x = MidiReadFile("test.mid")
End Sub
Actually I cannot run these code, the program and the VB development will be terminated when it try to execute the line :
x = MidiReadFile("test.mid")
I don't know if there is something wrong ( or missing
some procedure ). Would you please help me to find out
the problem.
Thank you very much
Barry