Handling C++ DLL string pointer

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

    #1

    Handling C++ DLL string pointer

    All,

    I have a C++ DLL that has the following function in it.

    LONG MYAPI myApi_FunctionN ame
    (
    LONG lDSType, /* i Source type */
    LPWSTR lptstrSource, /* io Source name */
    LONG lDSLength, /* i Length of lptstrSource */
    LPCWSTR lpctstrCat, /* i Catalogue */
    LPCWSTR lpctstrSubj /* i Subject */
    );

    I have the following declared in my VB2005 module.

    Public Declare Unicode Function myApi_FunctionN ame Lib "mydll.dll" (ByVal lDSType As Integer, _
    ByRef lptstrSource As Integer, _
    ByVal lDSLength As Integer, _
    ByVal lpctstrCat As String, _
    ByVal lpctstrSubj As String) As Integer

    If I declare lptstrSource as Integer, I get a numeric value. I believe it is the pointer address. The question is, how do I get the actual "Source name" string (i.e. lptstrSource)?
    I have tried passing lptstrSource as String. However, it is always empty.

    Thanks,

    alex

  • Mattias Sjögren

    #2
    Re: Handling C++ DLL string pointer

    >If I declare lptstrSource as Integer, I get a numeric value. I believe it is the pointer address. The question is, how do I get the actual "Source name" string (i.e. lptstrSource)?
    >I have tried passing lptstrSource as String. However, it is always empty.
    The string should be passed ByVal. If it's an output parameter,
    consider using the StringBuilder type instead.


    Mattias

    --
    Mattias Sjögren [C# MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    • penguin

      #3
      Re: Handling C++ DLL string pointer

      Mattias,

      It works perfectly. Thanks a lot.

      ^_^

      alex


      "Mattias Sjogren" <mattias.dont.w ant.spam@mvps.o rgwrote in message
      news:eb$I4ulyGH A.3428@TK2MSFTN GP02.phx.gbl...
      If I declare lptstrSource as Integer, I get a numeric value. I believe it
      is the pointer address. The question is, how do I get the actual "Source
      name" string (i.e. lptstrSource)?
      >>I have tried passing lptstrSource as String. However, it is always empty.
      >
      The string should be passed ByVal. If it's an output parameter,
      consider using the StringBuilder type instead.
      >
      >
      Mattias
      >
      --
      Mattias Sjögren [C# MVP] mattias @ mvps.org
      http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
      Please reply only to the newsgroup.

      Comment

      Working...