Announcement

Collapse
No announcement yet.

return String of PBDLL 6.0 to VB6.0

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

  • Fred Oxenby
    replied
    Tom, GetString was a function in a PB/DLL
    It was silly of me to use that function-name.
    Think of it as;
    Function AnyFunction(Byval x as string)Export as String
    -------
    Thanks anyway for your answer.That was the answer I hoped for..

    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

    Leave a comment:


  • Tom Hanlin
    replied
    If it's declared BYVAL..AS STRING on the PB/DLL side, use BYREF..AS STRING
    on the Visual Basic side.

    There's no need for GetString at all, as far as I know.

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

    Leave a comment:


  • Fred Oxenby
    replied
    Lance, if your answer was aimed at my question, you surely succeded in avoiding
    the question.

    The Question is simple:
    In a PB DLL There is a function like this
    Function GetString(Byval String)Export as String
    This function expects an (ANSI) OLE string handle (your word)
    Called from Powerbasic code the compiler vill recognize the Byval keyword
    and make a copy of the string and supply OLE string handle to the copy
    ------
    If I want to use this function from VB I have to declare it in a way that the VB-compiler
    correctly set up the call.
    To get VB to supply OLE string handle you use "BYREF STRING" in VB-declaration
    -----
    Later, if you want (in VB) to mimic the handling of Powerbasic "BYVAL STRING"
    you explicit instruct VB to use a copy of the string when calling the PB/DLL function
    ----
    MyString$ = GetString((orginalString$))


    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

    Leave a comment:


  • Lance Edmonds
    replied
    the "problem" is not with powerbasic, but with the way vb handles the byval and byref keywords differently when passing dynamic strings to dll's.

    when vb passes a byref string to a dll, vb passes a pointer to an (ansi) ole string handle to powerbasic. powerbasic can directly use this ole string handle pointer (since that is what pb uses internally for dynamic strings), so the powerbasic code will need to be expecting to receive a byref string.

    however, when vb passes the string byval to a dll, it converts the string from unicode to ansi and formats it as asciiz string, and passes a pointer to the string data to the dll. therefore, the powerbasic code must be written to accept a byref asciiz string.

    for more information, please consult the appendix on vb in the pb/dll helpfile, and the vb strings faq in the faq forum at http://www.powerbasic.com/support/pb...hread.php?t=26

    i hope this helps!


    ------------------
    lance
    powerbasic support
    mailto:[email protected][email protected]</a>

    Leave a comment:


  • Fred Oxenby
    replied
    Tom, No offence but
    When I wrote my answer, I was afraid of your discussion.
    I think it is a little bit confusing.
    Perhaps, and only perhaps it is possible for Mr Siqueira to change the DLL
    In normal case, you have a 'readyToUse function in the DLL, and have to find
    the best declaration for it.
    ---
    My understanding of 'Byval String' in Powerbasic is that when called from Powerbasic,
    the compiler creates a copy of the string and send this 'Byref String'
    in other words, 'Byval String' and 'Byref String' both expect a pointer to
    a string description, not string data.
    ---
    I would very much appreciate your comment/correction





    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

    Leave a comment:


  • Tom Hanlin
    replied
    VB does funny things with strings. If you specify BYVAL with a VB string,
    you should use ASCIIZ on the PowerBASIC side. If you don't use BYVAL with
    a VB string, you should use STRING on the PowerBASIC side.
    Code:
    ' If you have this in VB...
    Declare Sub Foo Lib "taco.dll" Alias "FOO" (Whatever As String)
    ' Use this in PowerBASIC:
    Declare Sub Foo (Whatever As STRING) Export
    Code:
    ' If you have this in VB...
    Declare Sub Foo Lib "taco.dll" Alias "FOO" (BYVAL Whatever As String)
    ' Use this in PowerBASIC:
    Declare Sub Foo (Whatever As ASCIIZ) Export

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

    Leave a comment:


  • amauri siqueira
    Guest replied
    dear i change a sholder in vb , but d'ont make correct.

    I use DIALOG DOEVENTS for result but d'ont result.


    Please help me

    Amauri

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

    Leave a comment:


  • Fred Oxenby
    replied

    You should declare this way in VB 6.0
    Code:
    Public Declare Function CompactaNumero Lib "TACO.DLL" Alias "COMPACTANUMERO" (ByRef Amimi As String) As String 
    
    This is the correct way to interpret the PB-function
    
    Function CompactaNumero(Byval Amimi As String)Export as String
     ....
    End Function
    But what are your Dialog Doevents doing in your DLL-function?

    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se



    [This message has been edited by Fred Oxenby (edited January 24, 2001).]

    Leave a comment:


  • amauri siqueira
    Guest started a topic return String of PBDLL 6.0 to VB6.0

    return String of PBDLL 6.0 to VB6.0

    I work with VB using dll of PBDLL 6.0
    I have had some problems because,

    I declare this way in VB 6.0

    Public Declare Function CompactaNumero Lib "TACO.DLL" Alias "COMPACTANUMERO" (ByVal Amimi As String) As String


    The function in Power Basic DLL 6.0
    FUNCTION CompactaNumero ALIAS "COMPACTANUMERO" (BYVAL Amimi AS STRING) EXPORT AS STRING
    LOCAL largo AS INTEGER
    LOCAL vitima AS STRING
    LOCAL retorno AS STRING
    LOCAL intermedio AS DOUBLE
    LOCAL RecibeMIMI AS STRING
    DIALOG DOEVENTS
    RecibeMIMI = Amimi
    retorno= mid$(Amimi ,1,2)
    DIALOG DOEVENTS
    CompactaNumero = retorno

    END FUNCTION

    it sometimes returns me a correct value and other times it returns me incoherences.

    please help me


    Amauri

    ------------------
Working...
X