Handling .dll files

spurs

Active Member
Joined
Oct 18, 2006
Messages
479
Office Version
  1. 2016
  2. 2013
  3. 2010
  4. 2007
  5. 2003 or older
Platform
  1. Windows
I am writing VBA code that has to interact with a .dll file named master.dll which will be located on a USB memory stick (for example possibly drive E: F: or G:. In each case the subdirectory where master.dll is located will be in a subdirectory called Tickets

So the .dll file can be
any drive letter X followed by
X:\Tickets\Master.dll

The excel file containing the VBA code can be run from a different drive than where the Master.dll resides

I realize that I need a statement something like:
Private Declare Function MasterRT Lib "X:\Tickets\Master.dll" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer

1) If I don't know the letter of the drive where the USB is plugged in; how should I code the above line?
2) How can I trap the error if Master.dll is not found or available ? If this is the case I want to properly shut down the macro.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Not sure if your dll will support aliases but try the following and see if it works for you :

Code:
Option Explicit

Private Declare Function C_MasterRT Lib "C:\Tickets\Master.dll" Alias "MasterRT" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
Private Declare Function D_MasterRT Lib "D:\Tickets\Master.dll" Alias "MasterRT" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
Private Declare Function E_MasterRT Lib "E:\Tickets\Master.dll" Alias "MasterRT" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
Private Declare Function F_MasterRT Lib "F:\Tickets\Master.dll" Alias "MasterRT" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
Private Declare Function G_MasterRT Lib "G:\Tickets\Master.dll" Alias "MasterRT" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer


Sub Test()

    Dim oFSO As Object, oDrv As Object, lPathLength As Long
    Dim lErrNumer As Long, sErrDescription As String
    Dim lpBuffer As String, nSize As Integer
    
    lpBuffer = "Hello":       nSize = 5
    
    Set oFSO = CreateObject("Scripting.FileSystemObject")

    For Each oDrv In oFSO.Drives
    
        On Error Resume Next
        lPathLength = Len(Dir(oDrv.DriveLetter & ":\Tickets\Master.dll"))
        
        If lPathLength Then
            Select Case oDrv.DriveLetter
                Case "C"
                    Debug.Print C_MasterRT(lpBuffer, nSize)
                Case "D"
                    Debug.Print D_MasterRT(lpBuffer, nSize)
                Case "E"
                    Debug.Print E_MasterRT(lpBuffer, nSize)
                Case "F"
                    Debug.Print F_MasterRT(lpBuffer, nSize)
                Case "G"
                    Debug.Print G_MasterRT(lpBuffer, nSize)
            End Select
            Exit For
        End If
        
    Next oDrv
    
    lErrNumer = Err.Number
    sErrDescription = Err.Description
    If lErrNumer Then
        On Error GoTo 0
        Err.Raise lErrNumer, , sErrDescription
    End If

End Sub
 
Last edited:
Upvote 0
This works fine
Thank you !
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top