Announcement

Collapse
No announcement yet.

C++ to PB

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

  • C++ to PB

    Here's a function from a sample C++ program that I'm trying to
    convert to PB.

    int GetName(char* szBuffer, int* pnBufferSize)

    Here is what I'm doing
    Function GetName ALIAS "GetName" (szBuffer as ASCIIZ, pnBufferSize as LONG) export as Long


    I'm guessing that I should be doing something different with
    pnBufferSize since its a pointer, but I'm not sure what.

    Any pointers? No pun intended

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


    [This message has been edited by Brad Warmuskerken (edited December 03, 2003).]

  • #2
    Well,

    In PB, you can go ahead and specify your buffer size before hand, (ie: szBuffer AS ASCIIZ*255). ASCIIZ will automatically null terminate the string for you, so if the name is 70 characters, when you check the length, it will be 70. As well, you could return the name variable as a string from the function.

    Also, technically, in PB, unless you specify the BYVAL keyword in passing of parameters, the default is BYREF which is actually passing a pointer to the data to your FUNCTION.

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




    [This message has been edited by Adam J. Drake (edited December 03, 2003).]
    Adam Drake
    Drake Software

    Comment


    • #3
      Thanks Adam.

      I guess I should have stated that I'm more confused about how
      to declare in PB the pointer to the integer in C++.

      In PB help, it has char* as ASCIIZ, but nothing for int*

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

      Comment


      • #4
        Brad,

        Int* is a pointer to a 32 bit number. So what you've done should work.

        Russ Srole

        ------------------
        "There are two novels that can change a bookish fourteen-year old's life: The Lord of the Rings and Atlas Shrugged. One is a childish fantasy that often engenders a lifelong obsession with its unbelievable heroes, leading to an emotionally stunted, socially crippled adulthood, unable to deal with the real world. The other, of course, involves orcs." - John Rogers

        Comment


        • #5
          "int* var" translates to "ByRef var As Long" in PB, so your translation is correct (the default is ByRef).

          ------------------
          Kev Peel
          http://www.kgpsoftware.com
          kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

          Comment


          • #6
            The translation mostly depends of how you are going to use the function.
            This function apparently is designed to work with any kind of buffer, not
            only asciiz strings, otherwise will not need that you pass the length of
            the buffer. So, if you want to use an asciiz string, declare it as:
            Code:
            Declare Function GetName ALIAS "GetName" (szBuffer as ASCIIZ, BYVAL pnBufferSize as LONG) export as Long
            and use it passing the asciiz string and the SIZEOF of this string.

            If you want to use a dynamic string, declare it as:
            Code:
            Declare Function GetName ALIAS "GetName" (BYVAL szBuffer as DWORD, BYVAL pnBufferSize as LONG) export as Long
            and use it passing the STRPTR of the dynamic string and the LEN of this string,
            that must be initialized with spaces. There are more possible variations, like
            using an array of bytes or a fixed length string.



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

            Comment

            Working...
            X