Announcement

Collapse
No announcement yet.

passing strings VB.net to PB9

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

  • passing strings VB.net to PB9

    sending a string to a DLL I made a function in the DLL:

    FUNCTION ReverseString ALIAS "ReverseString" (BYVAL X AS STRING) EXPORT AS STRING
    MSGBOX X
    A$ = X
    MSGBOX A$
    S$ = STRREVERSE$(X)
    FUNCTION = S$ + " test dll"
    END FUNCTION

    the first message box shows the string the second shows blanks and the only thing that comes back from the function is " test dll"

    the declare in VB.NET is:

    <DllImport("TESTDLL.DLL")> _
    Public Shared Function ReverseString(ByVal X As String) As String
    End Function

    Does anyone have an answer in passing a string to a native DLL?


    Thanks

  • #2
    Passing Strings

    Hi Kerry;

    Code:
    'This should work.
    FUNCTION ReverseString ALIAS "ReverseString" (BYREF X AS STRING) EXPORT AS STRING
    
    'Items passed BYVAL cannot be changed.
    FUNCTION ReverseString ALIAS "ReverseString" (BYVAL X AS STRING) EXPORT AS STRING

    Comment


    • #3
      Originally posted by Walter Thompson View Post
      Hi Kerry;

      Code:
      'This should work.
      FUNCTION ReverseString ALIAS "ReverseString" (BYREF X AS STRING) EXPORT AS STRING
      
      'Items passed BYVAL cannot be changed.
      FUNCTION ReverseString ALIAS "ReverseString" (BYVAL X AS STRING) EXPORT AS STRING
      I do not need to pass back the variable in the parameter the function sends the string back.

      Thanks.

      Comment


      • #4
        Kerry,

        The code below seems to work for me with:
        - PBWin 9.0 for the dll
        - Visual Basic 2005 Express Edition for the calling program.

        the PB dll:
        Code:
        #COMPILE DLL "Test.dll"
        #DIM ALL
        #INCLUDE "Win32Api.Inc"
        
        FUNCTION ReverseString ALIAS "ReverseString" (BYVAL X AS STRING) EXPORT AS STRING
            LOCAL S$
            S$ = STRREVERSE$(X)
            MSGBOX "In PB dll:" + S$
            FUNCTION = S$ + " test dll"
        END FUNCTION 
        
        
        '--------------------------------------------------------------
        FUNCTION LIBMAIN(BYVAL hInstance AS DWORD, BYVAL fwdReason AS DWORD, BYVAL lpvReserved AS DWORD) EXPORT AS LONG
            LIBMAIN = 1
        END FUNCTION
        '--------------------------------------------------------------
        The VB code in Form1.vb:
        Code:
        Imports System.Threading
        Imports System.Runtime.InteropServices
        
        Public Class Form1
        
            Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                Dim sS As String
                sS = "Eddy"
                MsgBox("Answer of dll:" + MyClss.ReverseString(sS))
            End Sub
        End Class
        Add a class module to your VB project:
        Code:
        Public Class MyClss
        
            Declare Ansi Function ReverseString Lib "Test.dll" (ByVal a As String) As String
        
        End Class
        Kind regards
        Last edited by Eddy Van Esch; 9 Dec 2008, 03:05 PM.
        Eddy

        Comment


        • #5
          That did it.

          Thanks, I knew I could count on you guys!!

          Kerry

          Comment

          Working...
          X