Announcement

Collapse
No announcement yet.

Dll for Pascal, case sensitiviy in inc. file

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

  • Dll for Pascal, case sensitiviy in inc. file

    Hello,

    I'm writing a Dll file that a customer needs for his Pascal
    program. I'm fairly new to Dll file creation, and would appreciate
    any assistance here. The customer would like to be able to write
    his Pascal header/include file in the same standard format he's
    accustomed to. There will be several simple functions in the PowerBasic
    Dll that look like this:

    Code:
    FUNCTION Set_Array_Value (BYVAL Array_Index AS LONG,BYVAL Value AS SINGLE) EXPORT AS LONG
      Array_Value(Array_Index)= Value
    END FUNCTION
    Small arrays similar to this will be global to and operated on mostly from
    within my Dll, as this is for a high speed physical simulation and it's
    necessary to avoid as many function calls on his end as possible. Currently,
    his Pascal declaration for a function like this appears as:
    Code:
    function SET_ARRAY_VALUE(Array_Index: Integer; Value: Single): integer; stdcall; external 'The.dll';
    However, since a capitalized function declaration is unusual in his
    work, he would like to declare it as follows:
    Code:
    function Set_Array_Value(Array_Index: Integer; Value: Single): integer; stdcall; external 'The.dll';
    The PowerBasic test version of the declaration (.Inc file) works fine and
    looks like:
    Code:
    DECLARE FUNCTION Set_Array_Value LIB "THE.DLL" 
    (BYVAL Array_Index AS LONG, BYVAL Value AS SINGLE) AS LONG
    He suggested changing the function itself inside my DLL to include an
    ALIAS as follows:
    Code:
    FUNCTION Set_Array_Value ALIAS "Set_Array_Value" (BYVAL Array_Index AS LONG,BYVAL Value AS SINGLE) EXPORT AS LONG
      Array_Value(Array_Index)= Value
    END FUNCTION
    He hoped that the above change to my Dll function would enable
    him to use mixed/lowercase letters in his Pascal declaration, i.e.:

    Code:
    function Set_Array_Value(Array_Index: Integer; Value: Single): integer; stdcall; external 'the.dll';
    However, when changing the Dll function to include the ALIAS, the
    function does not appear to get called at all by my PowerBasic EXE test
    program. If it is possible, how can I change the Dll function itself to
    allow him to use the mixed case (Set_Array_Value) declaration on his end?

    Thank you, and I hope you all had a wonderful holiday season and a
    great New Year's Eve!!

    Todd Wasson
    Performance Simulations
    Drag Racing and Top Speed
    Prediction Software http://PerformanceSimulations.Com

    P.S. I just tried the following Dll change and it worked through the PowerBasic test
    EXE:
    Code:
    FUNCTION Set_Array_Value ALIAS "SET_ARRAY_VALUE" (BYVAL Array_Index AS LONG,BYVAL Value AS SINGLE) EXPORT AS LONG
      Array_Value(Array_Index)= Value
    END FUNCTION
    It seems that setting an ALIAS that exactly matches the function
    name itself is pointless, and does not work. Would the customer's
    following Pascal declaration work with the above Dll change?

    Code:
    function Set_Array_Value(Array_Index: Integer; Value: Single): integer; stdcall; external 'the.dll';
    ------------------




    [This message has been edited by Todd Wasson (edited December 31, 2000).]
    Todd Wasson
    http://PerformanceSimulations.Com
    PowerBasic Racing Simulator (October 2007 clip - 15.1MB wmv file) http:http://www.performancesimulations.co...m-GenIV-12.wmv

  • #2
    If in DLL FUNCTION Set_Array_Value ALIAS "Set_Array_Value" (BYVAL Array_Index AS LONG,BYVAL Value AS SINGLE) EXPORT AS LONG
    in Exe should be DECLARE FUNCTION Set_Array_Value LIB "THE.DLL" ALIAS "Set_Array_Value" (BYVAL Array_Index AS LONG, BYVAL Value AS SINGLE) AS LONG

    ------------------
    E-MAIL: [email protected]

    Comment


    • #3
      Semen,
      Thank you for your quick reply. I tried this, but now, the function
      does not appear to get called at all. Placing a MSGBOX inside the Dll
      function resulted in nothing. Perhaps I am making a mistake somewhere else?

      In EXE/INC.:
      Code:
      DECLARE FUNCTION Set_Array_Value LIB "THE.DLL" ALIAS "Set_Array_Value" (BYVAL Array_Index AS LONG, BYVAL Array_Value AS SINGLE) AS LONG
      ''Calling the function itself
      Set_Array_Value 1,10.3
      In DLL:
      Code:
      FUNCTION Set_Array_Value ALIAS "Set_Array_Value" (BYVAL Array_Index AS LONG, BYVAL Array_Value AS SINGLE) EXPORT AS LONG
       Array_Stored_Value(Array_Index) = Array_Value
       MSGBOX STR$(Array_Stored_Value(Array_Index))
      END FUNCTION
      I'm stumped here. Where else could I be making a mistake?
      Thanks,
      Todd


      ------------------
      Todd Wasson
      http://PerformanceSimulations.Com
      PowerBasic Racing Simulator (October 2007 clip - 15.1MB wmv file) http:http://www.performancesimulations.co...m-GenIV-12.wmv

      Comment


      • #4
        Todd --
        This works fine on my PC

        Exe:
        Code:
           #Compile Exe
           Declare Function Set_Array_Value Lib "THE.DLL" Alias "Set_Array_Value" (ByVal Array_Index As Long, ByVal Array_Value As Single) As Long
           Function PbMain
              Set_Array_Value 1, 10.3
           End Function
        Dll:
        Code:
          #Compile Dll "THE.DLL"
          Function Set_Array_Value Alias "Set_Array_Value" (ByVal Array_Index As Long, ByVal Array_Value As Single) Export As Long
             Dim Array_Stored_Value(10) As Global Single
             Array_Stored_Value(Array_Index) = Array_Value
             MsgBox Str$(Array_Stored_Value(Array_Index))
          End Function
        Because in DLL you use an array Array_Stored_Value, I added it's declaration.






        ------------------
        E-MAIL: [email protected]

        Comment


        • #5
          Thank you, Semen. As usual, you are correct! I had made the mistake
          of using an incorrect #INCLUDE in my test EXE, which was referencing
          an out of date file. By placing the DECLARE FUNCTION line in the EXE
          itself, the code worked immediately. By changing the #INCLUDE line to
          access the CORRECT file with your declaration, it worked.

          Thanks again,
          Todd

          ------------------
          Todd Wasson
          http://PerformanceSimulations.Com
          PowerBasic Racing Simulator (October 2007 clip - 15.1MB wmv file) http:http://www.performancesimulations.co...m-GenIV-12.wmv

          Comment


          • #6
            I was just peruzing through this and curious myself, as a refresher...

            I understand PowerBasic exports all uppercase, is that correct?

            Except that PB EXE's can see the functions, whereas C or pascal or whatnot cannot unless they call all uppercase???


            SO hence an Alias statement is added to give the mixed case for other compilers?


            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


            • #7
              Scott,
              I think the key is that PB defaults to uppercase, and an alias
              is used to override that default. When PB calls a PB DLL, if neither
              use an alias, they both use upper case and there is no problem. If
              the DLL uses an alias, though, the calling pgm must use a matching alias
              to override its upper case default.



              ------------------
              Thanks,

              John Kovacich
              Thanks,

              John Kovacich
              Ivory Tower Software

              Comment


              • #8
                Internally, the compiler capitalizes all variable and sub/function names during the compilation process to ensure the compiler is case-insensitive to things like "MyVariable&" and "myvariable&", etc. By default, all exported and imported subs/functions are expected to be capitalized unless an explicit ALIAS clause is added to the appropriate prototype (sub/function definition) or DECLARE statement. Therefore, the ALIAS clause is provided to provide compatibility with other languages that may use mixed-case.

                Win32 (unlike Win16) is case-sensitive to exported/imported names, so ALIAS's often necessary to ensure that the target sub/function of an external module can be found by Windows during linking.

                However, if you are writing your own DLL's for use with PowerBASIC, the use of ALIAS is essentially optional, since PB is consistent with it's capitalization of export and import sub/function names. That is, if you do not use ALIAS anywhere in your code, PowerBASIC and Windows will be able to resolve the target name successfully because everything will be capilatized.

                Clear as mud?


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

                Comment


                • #9
                  NOpe, clear as glass! That's about what Jim Hugeley told me (Jim where are you??)...


                  And that makes sense, the part I did not understand was the import part, so if PB capitializes that too, life's great.
                  I've never used the Alias but one time when a customer was using Boar land (Borland) to do his project....




                  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

                  Working...
                  X