Announcement

Collapse
No announcement yet.

C construct help please

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

  • C construct help please


    What is the proper PowerBasic DLL v6-7 function export type
    if the C construct is a return of LPLong.

    Thank You.

    Bruce



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

  • #2
    The LP prefix means "pointer". A C long is a PowerBASIC LONG. So,
    you're looking at a generic 32-bit return value-- use a DWORD or
    a LONG-- and understand that the result is actually a pointer to
    a LONG value. (Because FUNCTION..AS LONG PTR isn't valid syntax,
    but you can always return a LONG PTR as a LONG or a DWORD, since
    the data types are effectively the same under 32-bit Windows).


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

    Comment


    • #3

      Thx Tom:

      I'm familar with the syntax.
      As Export Long Ptr was not valid, and Long or Dword is not working, I thought maybe I was doing something wrong.

      I guess I still am.

      Thx again for the prompt post.

      Bruce

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

      Comment


      • #4
        a pointer is a long (or dword), just do an export DWORD ...
        e.g.

        Code:
        function getLongPointer alias "getLongPointer" (iLong as Long) export as Long
          function = varptr(iLong)
        end function
        ------------------
        dickinson.basicguru.com
        Don Dickinson
        www.greatwebdivide.com

        Comment


        • #5

          Well, It should have worked, but alas.

          I need to get the contains of the supposedly LPLong.

          The @ affixed to the returned LPLong/Dword/Long does not get the desired value.

          Very Annoying.

          Thx everyone for your help.

          Bruce



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

          Comment


          • #6
            It should be very easy... just assign the DWORD/LONG return value to a local pointer of the right data type:
            Code:
            DIM px AS LONG PTR, x AS LONG
            px = RetLongPointer(param)
            x = @px
            ...
            FUNCTION RetLongPointer() AS DWORD
              STATIC result AS LONG ' the returned pointer target must be persistent
                                    ' so returning a pointer to a LOCAL is BAD, BAD, BAD!  
              ... code here that generates the value stored in 'result'
              FUNCTION = VARPTR(result)
            END FUNCTION
            ------------------
            Lance
            PowerBASIC Support
            mailto:[email protected][email protected]</A>
            Lance
            mailto:[email protected]

            Comment


            • #7
              Is the LpLong a parameter to a function call or the return value
              of the function?

              If a parameter, simply use a LONG variable BYREF when calling.

              If a return type, Lance's sample above should work.


              ------------------
              Bernard Ertl
              Bernard Ertl
              InterPlan Systems

              Comment

              Working...
              X