Announcement

Collapse
No announcement yet.

VBAPI.INC

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

  • VBAPI.INC

    Ok.. Now that I can link 32bit PB DLL's with VB5.. I have another issue.
    I am trying to return string variables from PB to VB5. I tried
    to import the VBAP.INC but I get an error. Is there a VBAPI32.INC
    available yet? Or how can I return strings (ASCIIZ) from PB to VB5?

    Also, I would like to know the 32bit PowerBasic equivalent to GetStrAlloc
    and RlsStrAlloc..


    ------------------
    Explorations v3.0 RPG Development System http://www.explore-rpg.com

    [This message has been edited by Tyrone W. Lee (edited April 18, 2001).]
    Explorations v9.10 RPG Development System
    http://www.explore-rpg.com

  • #2
    Something like this?

    Code:
     
    [b]PB: The DLL[/b]
    FUNCTION MAKEUCASE(inString AS ASCIIZ PTR) EXPORT AS STRING
    ON ERROR RESUME NEXT
    FUNCTION = UCASE$(@inString)
    END FUNCTION
     
    [b]VB: Calling the DLL[/b]
    Private Declare Function MAKEUCASE Lib "myucase.dll" (ByVal inString As String) As String
    Private Sub Form_Load()
    Dim TestString As String
    TestString = "test"
    MsgBox "MAKEUCASE returned " & MAKEUCASE(ByVal TestString)
    Best of luck,
    Wayne


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

    Comment


    • #3
      Passing strings back and forth with VB is covered in the help file under "Appendix B", and in the FAQ forum...


      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Ok.. I found out how to pass strings in PB6.0.. But what about
        dynamic memory allocation. GetStrAlloc and RlsStrAlloc? I have
        a v2.0 .DLL that uses these function heavily with pointers and
        I need a v6.0 equivalent.

        Please help me on this one? If there isn't a command can I use
        PB v2.0 and link it with v6.0?

        ------------------
        Explorations v3.0 RPG Development System
        http://www.explore-rpg.com
        Explorations v9.10 RPG Development System
        http://www.explore-rpg.com

        Comment


        • #5
          Under PB/DLL 6, you do dynamic memory allocation using the Win32API calls GlobalAlloc/HeapAlloc, GlobalLock and GlobalUnlock and GlobalFree.

          (All the Globalxxx have a companion Heapxxx function).

          MCM


          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Tyrone,

            Is the intention is to create temporary strings, why not
            let PB do it for you? Just use a regular string and initialize
            it to the size you need?

            If you need ASCIIZ, just add CHR$(0) to the end...

            Ie.:

            Code:
            LOCAL TempStringSpace$
            LOCAL BytePtr AS BYTE PTR
            
            TempStringSpace$ = SPACE$( NumBytesNeeded&)
            BytePtr = STRPTR( TempStringSpace$)
            'Process string with pointer...
            ....
            'Release old string space, create new space
            TempStringSpace$ = SPACE$( NumBytesNeeded&)
            BytePtr = STRPTR( TempStringSpace$)
            'Process string with pointer...


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

            Comment


            • #7
              I want to allocate memory blocks to form a link list of data. (Database
              records.)

              I have several databases on disk that I load into and manipulate
              in memory as if they were on disk. Basically a memory random access
              file. You can read, write, append, and instert records in memory
              as if u were writing to disk.

              I can't use arrays because there are several of these databases in
              operation at the same time. (not all the same size) So arrays
              would waste memory space.

              I will check out the Windows memory Allocate command but PB should
              really include the original GetStrAlloc, RlsStrAlloc from v2.0
              Its a MUCH NEEDED command for real pointer Link Lists..



              ------------------
              Explorations v3.0 RPG Development System
              http://www.explore-rpg.com
              Explorations v9.10 RPG Development System
              http://www.explore-rpg.com

              Comment


              • #8
                If you want to allocate strings dynamically use the
                SysAllocStringByteLen() function to allocate and
                SysFreeString() to free the string. As in the following
                example:

                Code:
                #COMPILE EXE
                 
                DECLARE FUNCTION SysAllocStringByteLen LIB "OLEAUT32.DLL" ALIAS "SysAllocStringByteLen" ( _
                                                                                    szOleChar AS ASCIIZ, _
                                                                                    BYVAL lLen AS LONG _
                                                                                    ) AS DWORD
                                                                                             
                DECLARE SUB SysFreeString LIB "OLEAUT32.DLL" ALIAS "SysFreeString" ( BYVAL dwBstr AS DWORD )
                 
                SUB TestString( szString AS ASCIIZ )
                     
                    STDOUT szString
                     
                END SUB
                 
                FUNCTION PBMAIN() AS LONG
                    LOCAL pszString AS ASCIIZ PTR
                     
                    pszString = SysAllocStringByteLen( "HELLO THERE", 11 )
                     
                    CALL TestString( @pszString )
                     
                    CALL SysFreeString( pszString )
                     
                    WAITKEY$
                     
                END FUNCTION

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

                Comment


                • #9
                  Nifty.. I will save that information.. Though, I have just converted
                  my code to use an array buffer that holds multiple linked lists
                  within it by index.

                  I use the PRESERVE command to ReDIM a larger array as new elements
                  are added to the link list..

                  But I'll save those API commands for later.



                  ------------------
                  Explorations v3.0 RPG Development System
                  http://www.explore-rpg.com
                  Explorations v9.10 RPG Development System
                  http://www.explore-rpg.com

                  Comment

                  Working...
                  X