Announcement

Collapse
No announcement yet.

Simple DLL function question--Data type conversion

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

  • Todd Wasson
    replied
    Excellent, Michael, thank you very much I never would have noticed the
    misplaced (totally absent) AS LONG. Now I understand that this defines the type
    of the return value. Exactly what I needed to know. Thanks again!


    Joseph, I just noticed how "FUNCTION = x" could be used instead of F
    FunctionName = x. That will speed things up a little on my end. Thank you.

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


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

    Leave a comment:


  • Michael Mattias
    replied
    On your first effort you had testfloattoint returing a single because your DECLARE did not specify an AS [type] for the return, so it was returing a SINGLE because a DEFSNG was in effect.

    in DLL
    Code:
    FUNCTION TestFloatToInt (X AS SINGLE) EXPORT AS LONG
     dim A as LONG
     A = INT(X)
     FUNCTION = A
    END FUNCTION
    In the using program:
    Code:
    DECLARE FUNCTION TestFloatToInt ALIAS "whateever" LIB "whatever" (X AS SINGLE)AS LONG
    MCM


    Leave a comment:


  • Joseph W Murphy
    replied
    I always use FUNCTION = a

    not TestFloattoInt = a

    to set the value of a function in PowerBasic. This is different from VB

    Joe Murphy

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

    Leave a comment:


  • Todd Wasson
    replied
    Thank you for your reply, Michael. The DLL will be necessary for my
    purposes. A Pascal or other language program will be calling my DLL.
    One basic thing I need to do here is pass and convert parameters the way
    the customer wants. The final purpose of the DLL will not be to convert
    SINGLEs to LONGs, but it will be necessary to do at some point. Unfortunately, I've
    never created a DLL, have always used Subs and Globals instead of Function
    calls, and have never had a need to do this type of thing before. Can anyone
    answer my original question?

    Thanks for your assistance,
    Todd Wasson




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


    [This message has been edited by Todd Wasson (edited October 01, 2000).]

    Leave a comment:


  • Michael Mattias
    replied
    Might be a bit easier to just use the Cxxx, INT, FIX, and CEIL functions and eschew the DLL.

    DIM A AS LONG, B AS SINGLE
    A = CLNG(B)
    A = CEIL(B)
    A = INT(B)
    A = FIX(B)

    MCM


    Leave a comment:


  • Todd Wasson
    replied
    Phil,

    This DLL function also returns 0. I need to send a number like 17.3
    defined as a SINGLE, and return 17 to a LONG variable.

    Code:
    FUNCTION TestFloattoInt (x AS SINGLE) EXPORT AS LONG   
    TestFloattoInt = INT(x)
    END FUNCTION
    On the other hand, if I do this:

    Code:
    FUNCTION TestFloattoInt (x AS SINGLE) EXPORT AS SINGLE   
    TestFloattoInt = INT(x)
    END FUNCTION
    the code returns the correct number, but isn't it just a SINGLE with
    the .3 cut off? Or is it truly a LONG now?

    The reason for this is to create a DLL that a Pascal programmer will use.
    We need to make sure our data types mix correctly and compatability won't be
    a problem.

    Thanks


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

    Leave a comment:


  • Phil Tippit
    replied
    Todd,

    A long variable doesn't have decimal places, therefor
    you are getting a zero value, you are not using INT to
    get the value. Plus TestFloattoInt needs to be LONG Not
    Single.

    Phil

    Code:
    'your code
    FUNCTION TestFloattoInt (x AS SINGLE) EXPORT AS SINGLE
       DIM a AS LONG
       MSGBOX "PowerBasic DLL Message: Input value is " + STR$(x)
        a=x  
       TestFloattoInt = a
    END FUNCTION
    'new code
    
    FUNCTION TestFloattoInt (x AS SINGLE) EXPORT AS LONG
       TestFloattoInt = INT(x)
    END FUNCTION
    
    ' but why not just do
    a&=INT(x!) in your main program.
    ------------------

    Leave a comment:


  • Simple DLL function question--Data type conversion

    Hello,

    Suppose I want to call a DLL function that receives a SINGLE and returns a LONG.
    The only way I can get this to work at this point is to DIM a AS LONG in the DLL,
    and then EXPORT it AS SINGLE to a LONG in the main EXE. I know this is not the way
    to do this. In the DLL, how can I:
    Code:
     FUNCTION TestFloattoInt (x AS SINGLE) EXPORT AS **LONG**
    instead of EXPORT AS SINGLE? EXPORT AS LONG always returns a 0 in PBMAIN's MsgBox.
    What is the simplest way to do this?

    Code:
    #COMPILE EXE
    DEFSNG B-Z
    
    DECLARE FUNCTION TestFloattoInt LIB "DLLTEST2.DLL" ALIAS "TESTFLOATTOINT" (x AS SINGLE)' EXPORT AS LONG
    
    FUNCTION PBMAIN() AS LONG
    DIM a AS LONG
    x=32.155
    a=TestFloattoInt(x)
    MSGBOX STR$(a)
    END FUNCTION
    DLLTEST2.DLL:

    [code]

    #COMPILE DLL

    FUNCTION TestFloattoInt (x AS SINGLE) EXPORT AS SINGLE
    DIM a AS LONG
    MSGBOX "PowerBasic DLL Message: Input value is " + STR$(x)
    a=x
    TestFloattoInt = a
    END FUNCTION



    ------------------
Working...
X