Announcement

Collapse
No announcement yet.

Translation from C++ to PB

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

  • Translation from C++ to PB

    How do I create PB equivalent code?

    AIQSDKAPI BOOL FAR PASCAL GetTickerPriceData(LPSTR lpszTicker,LPSTR lpszDate, float *open, float *high, float *low,float *close, unsigned long *volume, unsigned long *openinterest);

    Here is my failed attempt:

    DECLARE FUNCTION GetTickerPriceData LIB "AIQSDKIF.DLL" ALIAS "[email protected]" _
    (ticker AS ASCIIZ, _
    description AS ASCIIZ, _
    tickerdate AS ASCIIZ, _
    qopen AS SINGLE PTR, _
    qhigh AS SINGLE PTR, _
    qlow AS SINGLE PTR, _
    qclose AS SINGLE PTR, _
    qvolume AS LONG PTR, _
    qoi AS LONG PTR _
    ) _
    AS INTEGER

    You will also note the inclusion of the decorated name;
    this was the only way I could get this entry point to
    execute.

  • #2
    Ron,

    try this. If your app produces an error, you should post the
    number of the error.


    DECLARE FUNCTION GetTickerPriceData LIB "AIQSDKIF.DLL" ALIAS "[email protected]" _
    (ticker AS ASCIIZ, _
    Byref description AS ASCIIZ, _
    Byref tickerdate AS ASCIIZ, _
    Byref qopen AS Double, _
    Byref qhigh AS Double, _
    Byref qlow AS Double, _
    Byref qclose AS Double, _
    Byref qvolume AS Dword, _
    Byref qoi AS Dword _
    ) AS dword


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

    Comment


    • #3
      If it's declared with the pascal calling convention, you should declare it BDECL.

      Code:
      DECLARE FUNCTION GetTickerPriceData BDECL LIB "AIQSDKIF.DLL" ...
      --Don

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

      Comment


      • #4
        Awright. <cracks knuckles> Let's take a look.

        AIQSDKAPI we can probably ignore; it's likely to be a macro that
        defines the import/export convention. BOOL means that the function
        returns a LONG. FAR PASCAL doesn't mean "far" or "Pascal"; it means
        STDCALL, the default Windows calling convention (don't ask). This
        is 32-bit code, right?

        C doesn't have a BYREF passing method-- that's where those pointers
        come in. We'll just convert the passing convention accordingly.
        LPSTR is, yes, ASCIIZ, and float is SINGLE. unsigned long
        is DWORD. So:
        Code:
        DECLARE FUNCTION GetTickerPriceData LIB "AIQSDKIF.DLL" ALIAS _
           "[email protected]" (lpszTicker AS ASCIIZ, lpszDate AS ASCIIZ, _
           xopen AS SINGLE, high AS SINGLE, low AS SINGLE, xclose AS SINGLE, _
           volume AS DWORD, openinterest AS DWORD) AS LONG
        Decorated name... is odd. The programmers may have muffed the
        calling convention. If this declare doesn't work, try CDECL.

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

        Comment


        • #5
          Ron,

          float is single (as in your example). I think BOOL is long (surely not 16-bit integer).
          Thorsten is right: you should use byref. Don is right too.
          This should do it:
          Code:
          declare function GetTickerPriceData bdecl lib "AIQSDKIF.DLL" alias "[email protected]" _
                  (lpszTicker as asciiz, lpszDate as asciiz, sOpen as single, sHigh as single, sLow as single, sClose as single, _
                   dwVolume as dword, dwOpeninterest as dword) as long
          Regrads
          Peter


          ------------------
          [email protected] www.dreammodel.dk

          [This message has been edited by Peter P Stephensen (edited April 02, 2002).]
          [email protected]
          www.dreammodel.dk

          Comment


          • #6
            Trust me on the FAR PASCAL-- it's meaningless. Just a leftover from
            16-bit Windows. It's #define'd away into STDCALL for 32-bit code.

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

            Comment


            • #7
              Thanks for all the replies. Here is what worked:

              DECLARE FUNCTION GetTickerPriceData LIB "AIQSDKIF.DLL" ALIAS "[email protected]" _
              (ticker AS ASCIIZ, _
              tickerdate AS ASCIIZ, _
              qopen AS SINGLE PTR, _
              qhigh AS SINGLE PTR, _
              qlow AS SINGLE PTR, _
              qclose AS SINGLE PTR, _
              qvolume AS DWORD PTR, _
              qoi AS DWORD PTR _
              ) _
              AS LONG

              Comment


              • #8
                This should work too (and is easier to work with):
                Code:
                DECLARE FUNCTION GetTickerPriceData      LIB "AIQSDKIF.DLL"  ALIAS "[email protected]"  _
                                                              (ticker       AS ASCIIZ, _
                                                               tickerdate   AS ASCIIZ, _
                                                               qopen        AS SINGLE, _
                                                               qhigh        AS SINGLE, _
                                                               qlow         AS SINGLE, _
                                                               qclose       AS SINGLE, _
                                                               qvolume      AS DWORD,  _
                                                               qoi          AS DWORD  _
                                                               ) _
                                                               AS LONG
                Regards
                Peter

                ------------------
                [email protected]
                www.dreammodel.dk
                [email protected]
                www.dreammodel.dk

                Comment

                Working...
                X