Announcement

Collapse
No announcement yet.

Callback - Strings

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

  • Callback - Strings

    My Powerbasic dll is calling a VB function sent through Addressof.
    Now I am able to call the function and pass the Long values, but not the strings.
    Is there any other simple way then passing the pointer of the string to VB and then reading it from there. Simpley passing the string gives me rubbish data at VB end.

    Thank You

    -------------
    Niraj Bhatt

  • #2
    Code:
    You can try to use this in your VB-application
      
    Private Declare Function lstrlenA Lib "kernel32" (ByVal PtrToString As Long) As Long
    Private Declare Sub PtrToString Lib "kernel32" Alias "RtlMoveMemory" (Byval ptrTo As Any, Byval ptrFrom As Any, ByVal BytesToCopy As Long)
       
    Public Function PB_Callback(ByVal lpMyString As Long) As Long
    Dim MyString$
    Dim StrLen As Long
    '--MakeYourPointerToString-------------   
       If lpMyString Then
        StrLen = lstrlenA(lpMyString)
        If StrLen Then 
         MyString$=Space(StrLen)
         Call PtrToString(MyString$,lpMyString,StrLen)
        End If 
       End If
    '--ContinueToDoYourJob-----------------
    ---YourCode---
    ---Etc     ---
    End Function
       
    In PB you will use callback-prototype
    Declare Function PB_CallBack(lpMyString as Asciiz)as long
       
    You call it like this
       
     Call DWord PBCB?? Using PB_Callback(Byval StrPtr(MyString$)) To result&
    I think it works


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

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

    Comment


    • #3
      That was exactly what I did not wanted to do. Is there not an easier way to do so.

      Comment


      • #4
        Private Declare Function lstrlenA Lib "kernel32" (ByVal PtrToString As Long) As Long
        Private Declare Sub PtrToString Lib "kernel32" Alias "RtlMoveMemory" (Byval ptrTo As Any, Byval ptrFrom As Any, ByVal BytesToCopy As Long)
        Code:
           
        Public Function StringFromPointer(ByVal lpMyString As Long) As String
        Dim MyString$
        Dim StrLen As Long
           If lpMyString Then
            StrLen = lstrlenA(lpMyString)
            If StrLen Then 
             MyString$=Space(StrLen)
             Call PtrToString(MyString$,lpMyString,StrLen)
            End If 
           End If
           StringFromPointer=Mystring$
        End Function
        Put this in a .BAS module and now you
        can resuse it as often as you wish
        Fred
        mailto:[email protected][email protected]</A>
        http://www.oxenby.se

        Comment

        Working...
        X