Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Search DLL before P/Invoke?

Search DLL before P/Invoke?

Scheduled Pinned Locked Moved C#
questionc++
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dominik Reichl
    wrote on last edited by
    #1

    Hello! I'm trying to do some P/Invoke, but the native DLL is an optional component, i.e. it isn't sure that it is present. How can I test if P/Invoke will be able to call the DLL? Best regards Dominik


    _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

    J A 2 Replies Last reply
    0
    • D Dominik Reichl

      Hello! I'm trying to do some P/Invoke, but the native DLL is an optional component, i.e. it isn't sure that it is present. How can I test if P/Invoke will be able to call the DLL? Best regards Dominik


      _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

      J Offline
      J Offline
      Jun Du
      wrote on last edited by
      #2

      Can you test the DLL's existence before calling DllImport()?

      Best, Jun

      D 1 Reply Last reply
      0
      • J Jun Du

        Can you test the DLL's existence before calling DllImport()?

        Best, Jun

        D Offline
        D Offline
        Dominik Reichl
        wrote on last edited by
        #3

        Well, I'd need to search in several directories (system directory, application directory, etc.), and even if I find a DLL it's not sure that this DLL is really a valid library (could be a text file for example)... Isn't there any way to test if a loadable DLL is present? Best regards Dominik


        _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

        J D 2 Replies Last reply
        0
        • D Dominik Reichl

          Well, I'd need to search in several directories (system directory, application directory, etc.), and even if I find a DLL it's not sure that this DLL is really a valid library (could be a text file for example)... Isn't there any way to test if a loadable DLL is present? Best regards Dominik


          _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

          J Offline
          J Offline
          Jun Du
          wrote on last edited by
          #4

          As far as I know, there is no way to test if a DLL is loadable, except for catching exceptions when DllImport fails.

          Best, Jun

          1 Reply Last reply
          0
          • D Dominik Reichl

            Well, I'd need to search in several directories (system directory, application directory, etc.), and even if I find a DLL it's not sure that this DLL is really a valid library (could be a text file for example)... Isn't there any way to test if a loadable DLL is present? Best regards Dominik


            _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            You might want to look into trying to load the .DLL using the Assembly class. You might also want to look into doing this in a seperate AppDomain so you can unload it. -- modified at 12:07 Friday 25th August, 2006

            Dave Kreskowiak Microsoft MVP - Visual Basic

            1 Reply Last reply
            0
            • D Dominik Reichl

              Hello! I'm trying to do some P/Invoke, but the native DLL is an optional component, i.e. it isn't sure that it is present. How can I test if P/Invoke will be able to call the DLL? Best regards Dominik


              _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

              A Offline
              A Offline
              Andy Moore
              wrote on last edited by
              #6

              No there is not. You could do interop to DllLoadLibrary to see if you can load the DLL this way. If it fails then the dll is not present.

              Deus caritas est

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups