I'm using multiple DLLs with the same name and I would like to have only one path for searching a DLL when using dllimport.
My code so far:
'Trying to remove default search paths
<System.AttributeUsage(System.AttributeTargets.Assembly Or System.AttributeTargets.Method, AllowMultiple:=False)>
Public NotInheritable Class DefaultDllImportSearchPathsAttribute
Inherits Attribute
End Class
'Trying to add my own path
<DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Public Shared Function SetDllDirectory(ByVal lpPathName As String) As Long
End Function
'Importing my DLL
<DllImport("A.dll", CallingConvention:=CallingConvention.StdCall)>
Public Shared Sub B(<MarshalAs(UnmanagedType.BStr)> ByRef X As String)
End Sub
Dim path As String = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\A\", "path", Nothing)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SetDllDirectory(path)
End Sub
It keeps loading another DLL and never reaches the stage of searching the DLL in the 'path'. How can I make this work?
References: How can I specify a [DllImport] path at runtime?