Announcement

Collapse
No announcement yet.

declaring dll function with return value

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

  • declaring dll function with return value

    i built gmpfr.dll as a combination of GMP and MPFR libs, but need some help with declares.
    why don't this work?
    Code:
    DECLARE SUB mpf_sgn CDECL LIB "gmpfr.dll" ALIAS "_mpf_sgn" (BYREF op AS mpf) AS LONG
    also, can someone please translate the following C structures to PB?

    Code:
    typedef enum
    {
      GMP_RAND_ALG_DEFAULT = 0,
      GMP_RAND_ALG_LC = GMP_RAND_ALG_DEFAULT /* Linear congruential.  */
    } gmp_randalg_t;
    
    /* Linear congruential data struct.  */
    typedef struct {
      mpz_t _mp_a;			/* Multiplier. */
      unsigned long int _mp_c;	/* Adder. */
      mpz_t _mp_m;			/* Modulus (valid only if m2exp == 0).  */
      unsigned long int _mp_m2exp;	/* If != 0, modulus is 2 ^ m2exp.  */
    } __gmp_randata_lc;
    
    /* Random state struct.  */
    typedef struct
    {
      mpz_t _mp_seed;		/* Current seed.  */
      gmp_randalg_t _mp_alg;	/* Algorithm used.  */
      union {			/* Algorithm specific data.  */
        __gmp_randata_lc *_mp_lc;	/* Linear congruential.  */
      } _mp_algdata;
    } __gmp_randstate_struct;

    ------------------
    as the salmon fish is compelled to go back to it's birthplace to spawn, so comes a day when man is compelled to go back to it's source.. GOD
    as the salmon fish is compelled to go back to it's birthplace to spawn, so comes a day when man is compelled to go back to it's source.. GOD

  • #2
    Johan,

    In PB, a SUB cannot return a value. So, replace "DECLARE SUB"
    with "DECLARE FUNCTION", and keep the rest of the DECLARE line
    the same. Then see how it works out.

    I'm sorry, I am not able to do the translation from C for you.


    ------------------
    clay at clayclear dot net

    Comment


    • #3
      Something like this:
      Code:
      %GMP_RAND_ALG_DEFAULT   = 0
      %GMP_RAND_ALG_LC        = %GMP_RAND_ALG_DEFAULT     'Linear congruential.
      
      '------------------------------- Linear congruential data struct. -------------
      Type Gmp_RanData_Lc
        mp_a      As MPZ_T                                'Multiplier.
        mp_c      As Dword                                'Adder.
        mp_m      As MPZ_T                                'Modulus (valid only if m2exp == 0).
        mp_m2exp  As Dword                                'If != 0, modulus is 2 ^ m2exp.
      End Type
      
      '------------------------------- Random state struct. -------------------------
      Type Gmp_Randstate_Struct
        mp_seed   As MPZ_T                                'Current seed.
        mp_alg    As Dword                                'Algorithm used.
        mp_lc     As GMP_RANDATA_LC Ptr
      End Type
       
      Function PBMain()
        Dim GRS As GMP_RANDSTATE_STRUCT
        GRS.mp_alg = %GMP_RAND_ALG_DEFAULT
      End Function
      Note: You cannot use a constant As a Type Member, you'll need to set mp_alg after DIM'ming it
      Also it's unknown what MPZ_T is...

      ------------------
      Regards,
      Peter



      [This message has been edited by Peter Lameijn (edited July 30, 2005).]
      Regards,
      Peter

      Comment


      • #4
        thanks Clay and Peter.
        Peter, mpz_t is the structure for gmp's multi-precision integer, something like:
        Code:
              TYPE MPZ_T              ' multiprecision integer
                  mp_alloc AS LONG
                  mp_size  AS LONG
                  mp_limb  AS LONG
              END TYPE
        thanks Peter for the translation.

        ------------------
        as the salmon fish is compelled to go back to it's birthplace to spawn, so comes a day when man is compelled to go back to it's source.. GOD

        [This message has been edited by Johan Klassen (edited July 30, 2005).]
        as the salmon fish is compelled to go back to it's birthplace to spawn, so comes a day when man is compelled to go back to it's source.. GOD

        Comment

        Working...
        X