Announcement

Collapse
No announcement yet.

LoadLib again

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • LoadLib again

    Interesting, but For some reason whether this function does not exist (It does, saw msdn on it) or what, I'm confused.

    Why do I have to declare the function, and then NOT be able to run the app because the function is not found in KERNEL32.DLL.

    If the function is not found I want to drive on, continue etc....
    But I can't run the function without declaring it??


    Thanks,

    Scott
    Code:
    'Declare Function IsDebuggerPresent Lib "kernel32" () As Long
    
    hLib = LoadLibrary("KERNEL32.DLL")
    procaddr = GetProcAddress(hLib,"IsDebuggerPresent")
    If IsFalse procaddr Then
       MsgBox "Could not find the function, or DLL:" & $CRLF & "IsDebuggerPresent, in KERNEL32.DLL",%MB_ICONSTOP,"Error loading library"
    Else
       Call Dword ProcAddr Using IsDebuggerPresent()
    End If
    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    Wait a second....

    If I rem out the actual Call Dword using then it runs, so it loads the lib just fine.


    So if the function does not exist, I should not try to run it but it still stops the app just by being compiled, it never even executes...
    So how can you tell if a DLL has the right function, if you attempt to load and can't you should be able to continue..

    I forgot how to do this..hehe..


    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    Comment


    • #3
      You need to Alias the call.
      Or if you need late loading, use a prototype without the DLL name


      ------------------
      hellobasic

      Comment


      • #4
        Scott;

        When using the CALL DWORD command you must always "prototype" the
        function/procedure call in a declare statement !

        ie.

        Code:
        Declare Function IsDebuggerPresentX () As Long
        
        ...
        
        hLib = LoadLibrary("KERNEL32.DLL")
        procaddr = GetProcAddress(hLib,"IsDebuggerPresent")
        If IsFalse procaddr Then
           MsgBox "Could not find the function, or DLL:" & $CRLF & "IsDebuggerPresent, in KERNEL32.DLL",%MB_ICONSTOP,"Error loading library"
        Else
           Call Dword ProcAddr Using IsDebuggerPresentX()
        End If
        You will notice the Declare statement doesn't need the LIB option, since
        you are using LoadLibrary !

        Also, you will notice I added a capital X to the procedure name. This is not required
        or necessary, but I do suggest always added a prefix or suffix to
        the actual procedure/function name to indicate to you that the declaration
        is to be used as a prototype for CALL DWORD. I like to simply add
        a capital X as a suffix, since it is simple.


        ------------------
        Chris Boss
        Computer Workshop
        Developer of "EZGUI"
        http://cwsof.com
        http://twitter.com/EZGUIProGuy

        Comment


        • #5
          Now that kinda makes some sense, except that the X has no value to it...or is that the point?

          I'll give it a shot, the docs say thefunction exists, my Win2k box says it does not
          Maybe it's for when you are in debug mode..


          Thanks!

          Scott

          ------------------
          Scott
          mailto:[email protected][email protected]</A>
          Scott Turchin
          MCSE, MCP+I
          http://www.tngbbs.com
          ----------------------
          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

          Comment


          • #6
            This function works fine on my PC under Win2000.
            Run a fragment in normal mode and under PB/DLL debugger.

            Code:
               #Compile Exe
               #Dim All
               #Register None
               #Include "Win32Api.Inc"
            
               Declare Function IsDebuggerPresent As Long
               
               Function PbMain
                  Dim hLib As Long, hProc As Dword, lResult As Long
                  hLib = LoadLibrary("KERNEL32.DLL")
                  hProc = GetProcAddress(hLib,"IsDebuggerPresent")
                  If IsFalse(hProc) Then lResult = 0 Else _
                     Call Dword hProc Using IsDebuggerPresent To lResult
                  If lResult Then MsgBox "Under debugger" Else MsgBox "Don't see a debugger"
               End Function
            ------------------
            E-MAIL: [email protected]

            Comment


            • #7
              Scott;

              The thing with the X in the Prototype Declaration is just something
              I do to distiguish Prototype Declarations from normal ones.

              When you go back to your code months later, you may think you are
              defining procedures in your own code (since if the LIB part is not
              there, it is likely a local declaration), rather than just a
              prototype declaration.

              It helps me read my own code later on, when I go back to it.


              ------------------
              Chris Boss
              Computer Workshop
              Developer of "EZGUI"
              http://cwsof.com
              http://twitter.com/EZGUIProGuy

              Comment


              • #8
                The thing with the X in the Prototype Declaration is just something
                I do to distiguish Prototype Declarations from normal ones.
                Or to put it another way: to distinguish between implicitly imported functions and explicitly imported functions. It is an good idea!



                ------------------
                Lance
                PowerBASIC Support
                mailto:[email protected][email protected]</A>
                Lance
                mailto:[email protected]

                Comment

                Working...
                X