Announcement

Collapse
No announcement yet.

Vb5 & PowerBasic..

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

  • Vb5 & PowerBasic..

    I am having trouble linking a .DLL I've compiled with PB2.0 with VB5..
    Every time I attempt to use a function in the .DLL is says the DLL isn't
    found. When I give the FULL path in the DECLARE statement, the VB
    application still doesn't see the .DLL

    Any idea why?

    It is a 16bit .DLL but I can't understand why VB5 won't recognize it..
    Does it need to be registered? If so, how do I register a custom
    stand alone .DLL in VB5?



    ------------------
    Explorations v3.0 RPG Development System
    http://www.explore-rpg.com
    Explorations v9.10 RPG Development System
    http://www.explore-rpg.com

  • #2
    You 'can't' use 16bit dlls from VB5 because VB5 is 32bits.
    You need to use a flat thunk wich is VERY hard (Forget it)
    (Under NT a problem)

    Vice versa, using a generic thunk from lets say VB3 (16bit) using a 32bit DLL is easy.

    I posted some code in the source section as example ~ a month ago..

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

    Comment


    • #3
      Read Chapter 4 in the PBDLL 2.0 manual. There is a supplied
      THUNK layer (direct32.dll). It's been so long since I've done
      this that i can't remember the details but it's well explained
      in the docs.

      ------------------

      Comment


      • #4
        Ok.. I've given up on the 16bit call from vb5.. Instead, I am trying
        to use VB5 to call a 32Bit .DLL..

        The HELP File tells me the LibMain function will be called by Windows
        and The LibMain() returns a 1, the OS will accept the .DLL..
        Anything else, and Windows will auto-matically unload the .DLL.

        I am running on Windows NT 2000 and my .DLL is automatically unloading
        when my .DLL is initialized. Does anyone know what Win2000NT is expecting
        my LibMain() to return?



        ------------------
        Explorations v3.0 RPG Development System
        http://www.explore-rpg.com
        Explorations v9.10 RPG Development System
        http://www.explore-rpg.com

        Comment


        • #5
          I don't remember thunking from 32-bit code to 16-bit code as being all that
          difficult under Win95-based OSes, although it's been a few years. It's said
          to be more of a problem under NT-based systems.

          DIRECT32.DLL doesn't work that well with current OSes and VB versions, but
          it's certainly worth a try.


          ------------------
          Tom Hanlin
          PowerBASIC Staff

          Comment


          • #6
            Well I am home and I am running Windows ME.. I can't get VB5 to see
            a PowerBasic 32Bit .DLL

            Heres is my code..

            #DIM ALL

            #COMPILE DLL "DISTANCE.DLL"
            #INCLUDE "WIN32API.INC"
            GLOBAL ghLibTest AS LONG
            GLOBAL gReason AS LONG
            GLOBAL gReserved AS LONG
            GLOBAL gNumOfTimes AS DWORD
            GLOBAL gNumOfCheck AS DWORD

            FUNCTION LibMain(BYVAL hInstance AS LONG, _
            BYVAL fwdReason AS LONG, _
            BYVAL lpvReserved AS LONG) EXPORT AS LONG

            ghLibTest = hInstance
            gReason = fwdReason
            gReserved = lpvReserved
            INCR gNumOfTimes

            SELECT CASE fwdReason

            CASE %DLL_PROCESS_ATTACH
            gNumOfCheck = 1234
            MSGBOX "%DLL_PROCESS_ATTACH" + CHR$(13,10) + "ghLibTest = " + FORMAT$(ghLibTest) + CHR$(13,10) + "gNumOfCheck = " + FORMAT$(gNumOfCheck) + CHR$(13,10) + "gNumOfTimes = " + FORMAT$(gNumOfTimes) + CHR$(13,10) + "gReserved = " + _
            FORMAT$(gReserved)
            LibMain = 1 'success!
            'LibMain = 0 'failure!
            EXIT FUNCTION
            CASE %DLL_PROCESS_DETACH

            MSGBOX "%DLL_PROCESS_DETACH" + CHR$(13,10) + "ghLibTest = " + FORMAT$(ghLibTest) + CHR$(13,10) + "gNumOfCheck = " + FORMAT$(gNumOfCheck) + CHR$(13,10) + "gNumOfTimes = " + FORMAT$(gNumOfTimes) + CHR$(13,10) + _
            "gReserved = " + FORMAT$(gReserved)
            EXIT FUNCTION
            CASE %DLL_THREAD_ATTACH
            MSGBOX "%DLL_THREAD_ATTACH" + CHR$(13,10) + "ghLibTest = " + FORMAT$(ghLibTest) + CHR$(13,10) + "gNumOfCheck = " + FORMAT$(gNumOfCheck) + CHR$(13,10) + "gNumOfTimes = " + FORMAT$(gNumOfTimes) + CHR$(13,10) + _
            "gReserved = " + FORMAT$(gReserved)
            EXIT FUNCTION
            CASE %DLL_THREAD_DETACH
            MSGBOX "%DLL_THREAD_DETACH" + CHR$(13,10) + "ghLibTest = " + FORMAT$(ghLibTest) + CHR$(13,10) + "gNumOfCheck = " + FORMAT$(gNumOfCheck) + CHR$(13,10) + "gNumOfTimes = " + FORMAT$(gNumOfTimes) + CHR$(13,10) + _
            "gReserved = " + FORMAT$(gReserved)
            EXIT FUNCTION
            END SELECT
            MSGBOX "Lib Main" + CHR$(13,10) + "ghLibTest = " + FORMAT$(ghLibTest) + CHR$(13,10) + "gNumOfCheck = " + FORMAT$(gNumOfCheck) + CHR$(13,10) + "gNumOfTimes = " + FORMAT$(gNumOfTimes) + CHR$(13,10) + _
            "gReason = " + FORMAT$(gReason) + CHR$(13,10) + "gReserved = " + FORMAT$(gReserved)
            'LibMain = 0 'failure!

            'LibMain = 1 'success!
            END FUNCTION


            FUNCTION distance(BYVAL x1%,BYVAL y1%,BYVAL x2%,BYVAL y2%) EXPORT AS INTEGER

            distance = SQR((x2%-x1%)^2 +(y2%-y1%)^2)

            END FUNCTION


            --------------------------------

            I copied the LibMain straight from the Help file and I made my own
            distance calculation call that I wanted to test..

            When I declare the function in VB5, the system will ATTACH the .DLL
            and then immediatelyt DETACH it.. Anyone know why?

            ------------------
            Explorations v3.0 RPG Development System
            http://www.explore-rpg.com
            Explorations v9.10 RPG Development System
            http://www.explore-rpg.com

            Comment


            • #7
              To see if it's the LIBMAIN, comment out the whole LIBMAIN procedure and rely
              on PB's default LIBMAIN handling.

              Chances are, though, your problem is mismatched symbol case. PB/DLL exports
              in uppercase by default. VB uses the specified case as a default. To make sure
              both sides agree, use the ALIAS clause. For example:
              Code:
              FUNCTION Foo ALIAS "Foo" (BYVAL ork AS LONG) AS LONG  ' PB
              
              Declare Function Foo Lib "whatever.dll" Alias "Foo" (ByVal ork As Long) As Long  ' VB
              ------------------
              Tom Hanlin
              PowerBASIC Staff

              Comment


              • #8
                Your function should look like this:
                Code:
                FUNCTION distance Alias "distance" (BYVAL x1%,BYVAL y1%,BYVAL x2%,BYVAL y2%) EXPORT AS INTEGER
                If you don't put in the alias, your VB declare MUST be in all upper case or your function won't be found.

                --Don


                ------------------
                www.basicguru.com/dickinson
                Don Dickinson
                www.greatwebdivide.com

                Comment


                • #9
                  I've tried removing the LibMain and I get the error "CANT FIND DLL entry point distance in C:\DISTANCE.DLL"

                  My Code is below..

                  #DIM ALL

                  #COMPILE DLL "DISTANCE.DLL"
                  #INCLUDE "WIN32API.INC"

                  FUNCTION distance (BYVAL x1 AS LONG,BYVAL y1 AS LONG,BYVAL x2 AS LONG,BYVAL y2 AS LONG) EXPORT AS LONG

                  distance = SQR((x2-x1)^2 +(y2-y1)^2)

                  END FUNCTION


                  VB DECLARE:

                  Declare Function DISTANCE Lib "C:\DISTANCE.DLL" Alias "distance" (ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long



                  ------------------
                  Explorations v3.0 RPG Development System
                  http://www.explore-rpg.com
                  Explorations v9.10 RPG Development System
                  http://www.explore-rpg.com

                  Comment


                  • #10
                    Ok guys .. I figured it out.. But someone should document this somewhere...

                    #DIM ALL

                    #COMPILE DLL "C:\DISTANCE.DLL"
                    #INCLUDE "WIN32API.INC"

                    FUNCTION DISTANCE ALIAS "Distance" (BYVAL x1 AS LONG,BYVAL y1 AS LONG,BYVAL x2 AS LONG,BYVAL y2 AS LONG) EXPORT AS LONG

                    DISTANCE = SQR((x2-x1)^2 +(y2-y1)^2)

                    END FUNCTION


                    In VB5 you must declare it like this..

                    Declare Function distance Lib "C:\DISTANCE.DLL" Alias "Distance" (ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long

                    or

                    Declare Function DISTANCE Lib "C:\DISTANCE.DLL" Alias "Distance" (ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long


                    The function is matched up by the Alias " " not by the actual functionname.
                    So PowerBasic EXPORTED Functions must have an Alias in order to be seen
                    by VB5? Why? Older versions could EXPORT functions without the use of an Alias?




                    ------------------
                    Explorations v3.0 RPG Development System
                    http://www.explore-rpg.com
                    Explorations v9.10 RPG Development System
                    http://www.explore-rpg.com

                    Comment


                    • #11
                      16-bit Windows expected uppercase symbols. 32-bit Windows allows case-sensitive
                      symbols. PowerBASIC (16-bit or 32-bit) always exports and imports using uppercase
                      by default. 32-bit versions of Visual Basic use the symbol as typed by the user
                      by default.

                      So, if you don't want to use ALIAS, you can always enter the symbol as DISTANCE
                      in the VB version, and it will work fine until someone comes along and
                      decides to change the case on you. After all, symbols are not normally case-sensitive
                      in VB code, so people don't think twice about changing it to suit themselves...

                      It is most prudent to use ALIAS on both the PB and VB sides to make sure that
                      you're getting just what you expect.

                      ------------------
                      Tom Hanlin
                      PowerBASIC Staff

                      Comment

                      Working...
                      X