[RESOLVED] [2008] DLLImport, check if dll exists
Code:
<DllImport("mydll.dll", _
CharSet:=CharSet.Unicode)> _
Private Shared Function BohlasFunk(ByVal LetterFunk As String) As Object
End Function
How can I make sure the dll exists before making this function available? I was hoping that within DLLImport there would be a option to skip on errors (like OnError:=Skip), but it appears there is not.
I can easily skip this function, but if it is available I would use it.
So how do I go about checking for this dlls existence - allowing this functions creation if it does?
Thanka you!
Re: [2008] DLLImport, check if dll exists
http://www.vbforums.com/showthread.php?t=284794 got me to a solution
Code:
Public Function IsDllRegistered()
On Error Goto EH:
Dim MyObject as Object
Set MyObject = CreateObject("MyDll.dll")
Set MyObject = Nothing
IsDllRegistered = True
Exit Function
EH:
IsDllRegistered = False
End Function
I check if IsDllRegistered=True before I call a function from the dll.
This is working for me so far, but if there are better solutions feel free to add them!
Re: [RESOLVED] [2008] DLLImport, check if dll exists
A DLL is just a file, so why not just use File.Exists? The only places a DLL would exist for you to use an exported function would be in the same folder as your application, which you can get using Application.StartupPath, or in the system32 or equivalent, which you can get using Environment.GetFolderPath.