How to Access a Dll for Visual Basic


1. Create a call to the DLL file. In this example, a call to a DLL that manages the hard drives on the machine is used. The following code creates a call to the file:
Declare Sub getdiskinfo Lib 'c:\myDLL' (ByVal drive As String, ByVal volume As String, free_space As Long)
2. Create variables to send to the function and variable that contains the return value. The following code is used to declare variables in Visual Basic:
Dim drive As String
Dim volume As String
Dim free As Long
Dim returnValue As Integer
3. Call the function and return a value. The following code illustrates how you use a DLL function in Visual Basic:
returnValue = getdiskinfo (drive, volume, free)
4. Display the result to verify your function results. The message box is used to test values in Visual Basic. The following code displays the return value from the 'getdiskinfo' function call:
MsgBox returnValue

0 comments:

Post a Comment