W32 Interop Advice Needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Slagle

    W32 Interop Advice Needed

    I have an old Win32 Dll that want to pass a string back to my app
    via one of the parameters (not the return value).

    I am seeing one way to do this is to dereference a StringBuilder
    instance. Is this possible in VB.NET?

    Another possible way might be
    <MarshalAs (UnmanagedType. VBByRefStr)>

    Does anyone have any experience with this?

    The documentation for the DLL includes a VB6 decleration
    containing keyword 'ByVal' for the string parameter, so I assume
    its not passing a BSTR, but rather an address for a null terminated
    series of ASCII characters.

    I cannot locate an example within the DLL's documentation to
    verify that a string has to be presized within VB6 prior to calling
    the DLL.

    Any insight appreciated.

    -John Slagle
    -Denver, CO






  • Dominique Vandensteen

    #2
    Re: W32 Interop Advice Needed

    can't you simply use byref?

    Public Declare Sub TheFuncation Lib "thedll.dll " (ByRef theString as
    String)


    dominique


    "John Slagle" <jrslagle.remov eme@mindspring. com> wrote in message
    news:umBqztZ8DH A.2308@TK2MSFTN GP11.phx.gbl...[color=blue]
    > I have an old Win32 Dll that want to pass a string back to my app
    > via one of the parameters (not the return value).
    >
    > I am seeing one way to do this is to dereference a StringBuilder
    > instance. Is this possible in VB.NET?
    >
    > Another possible way might be
    > <MarshalAs (UnmanagedType. VBByRefStr)>
    >
    > Does anyone have any experience with this?
    >
    > The documentation for the DLL includes a VB6 decleration
    > containing keyword 'ByVal' for the string parameter, so I assume
    > its not passing a BSTR, but rather an address for a null terminated
    > series of ASCII characters.
    >
    > I cannot locate an example within the DLL's documentation to
    > verify that a string has to be presized within VB6 prior to calling
    > the DLL.
    >
    > Any insight appreciated.
    >
    > -John Slagle
    > -Denver, CO
    >
    >
    >
    >
    >
    >[/color]


    Comment

    • John Slagle

      #3
      Re: W32 Interop Advice Needed


      "Dominique Vandensteen" <domi.vds_inser t@tralala_tenfo rce.com> wrote in
      message news:ORmtOva8DH A.360@TK2MSFTNG P12.phx.gbl...
      [color=blue]
      > can't you simply use byref?[/color]

      I was stuck in a VB6 mindset. I kept taking out the ByVal and VS.NET kept
      putting it back in.

      Doing this:

      Declare Function error4describe Lib _
      "C4FOX.DLL" Alias "error4describe VB" ( _
      ByVal c4%, _
      ByVal errCode As Int16, _
      ByVal extraInfo%, _
      ByRef desc1$, _
      <MarshalAs(Unma nagedType.LPStr )> ByRef desc2 As String, _
      <MarshalAs(Unma nagedType.VBByR efStr)> ByVal desc3 As String _
      ) As Int16

      I Get This (from IL dump):

      int16 error4describe(
      int32 c4,
      int16 errCode,
      int32 extraInfo,
      string& marshal( ansi bstr) desc1,
      string& marshal( lpstr) desc2,
      string marshal( byvalstr) desc3)
      cil managed preservesig

      Originally, I didn't think the BStr was what I wanted ('BYVAL' in the VB6
      declaration). But the 'VB' suffix in the Alias hints otherwise.

      It does appear as though I can do whatever I need. I just have to
      find the right combination.

      Thanks.
      [color=blue]
      >
      > Public Declare Sub TheFuncation Lib "thedll.dll " (ByRef theString as
      > String)
      >
      >
      > dominique
      >
      >
      > "John Slagle" <jrslagle.remov eme@mindspring. com> wrote in message
      > news:umBqztZ8DH A.2308@TK2MSFTN GP11.phx.gbl...[color=green]
      > > I have an old Win32 Dll that want to pass a string back to my app
      > > via one of the parameters (not the return value).[/color][/color]


      Comment

      • Tom Shelton

        #4
        Re: W32 Interop Advice Needed

        On 2004-02-12, John Slagle <jrslagle.remov eme@mindspring. com> wrote:[color=blue]
        > I have an old Win32 Dll that want to pass a string back to my app
        > via one of the parameters (not the return value).
        >
        > I am seeing one way to do this is to dereference a StringBuilder
        > instance. Is this possible in VB.NET?
        >
        > Another possible way might be
        ><MarshalAs (UnmanagedType. VBByRefStr)>
        >
        > Does anyone have any experience with this?
        >
        > The documentation for the DLL includes a VB6 decleration
        > containing keyword 'ByVal' for the string parameter, so I assume
        > its not passing a BSTR, but rather an address for a null terminated
        > series of ASCII characters.
        >
        > I cannot locate an example within the DLL's documentation to
        > verify that a string has to be presized within VB6 prior to calling
        > the DLL.
        >
        > Any insight appreciated.
        >
        > -John Slagle
        > -Denver, CO[/color]

        Pass a System.Text.Str ingBuilder ByVal...

        Dim sb As New StringBuilder(Y ourLengthHere)
        YourFunction(sb )
        Return sb.ToString()

        HTH
        --
        Tom Shelton [MVP]
        Powered By Gentoo Linux 1.4
        "Yes, it's the right planet, all right, " he said again.
        "Right planet, wrong universe. "

        Comment

        Working...