No announcement yet.

Creating string in PB to VB without stuffing

  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating string in PB to VB without stuffing

    I have created my DLL with a funtion and pass two strings to it.
    The second string I want to stick some status info in from PB.
    However, to get this to work, I have to pad the string prior calling PB.


    Declare MyFunc lib "MyDLL.DLL" (ByVal string1$, ByVal string2$) as long

    sub Command1_Click()
    dim rc as long
    dim string2 as string

    'I now have to create space in string2 so that PB can change it.
    string2 = space(200)
    rc= MyFunc("Test",string2)

    end sub

    My question is, how can I change it so that I don't need to
    'stuff' string2 prior to calling ?

    p.s. MyFunc has the two strings as ASCIIZ's



  • #2

    Unless you have some special need for ASCIIZ then...

    Declare MyFunc lib "MyDLL.DLL" ( string1 as string ) as String
    Dim sString as string
    Dim returnString as string
    sString = "Test"
    returnString = MyFunc(sString)
    Function MyFunc ( inString as string ) export as String    
        Function = String$(2048,"x")
    End function
    p.s. not tested but you get the idea.. Also if you don't want
    to make it into a function that returns a string. Just pass
    a second string as I passed the first one. No Byval and No
    ASCIIZ in PB..

    [email protected]

    [This message has been edited by Jim Huguley (edited July 31, 2000).]


    • #3
      My problem is that I need MyFunc to return a long and for string2
      to be passed back with 'stuff'. The only reason I'm using ASCIIZ's
      is that I thought that's what I had to use to pass info back.



      • #4
        Nope... Just pass your string2 (no ByVal) and declare
        as string in your PB function.. and you can modify or change.
        PB and VB both use OLE strings and VB handles the Unicode/Ansi
        conversions when passing to a DLL and back...

        [email protected]


        • #5
          Hi there,

          I agree with Jim, just use String's in your PB declarations.
          With 32bit VB they work fine. The only issue I ever had was when
          I got PB to callback to a VB function, passing a string on the way.
          To get the string to VB nicely, you need to convert it to Unicode
          in PB first, and then return it. I guess its because VB thinks the
          function was called by one of its own routines, and expects the
          string to be in Unicode (which I gather is what VB uses internally.)

          If you need more info, email me and I'll send a sample of what
          I'm blabbering on about.

          [email protected]



          • #6
            Thanks chaps, I'll give it a bash