Results 1 to 3 of 3

Thread: [RESOLVED] [2008] DLLImport, check if dll exists

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2008
    Posts
    72

    Resolved [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!

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Sep 2008
    Posts
    72

    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!

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width