Home All Groups Group Topic Archive Search About

Handling C++ DLL string pointer

Author
28 Aug 2006 3:49 AM
penguin
All,

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

LONG MYAPI myApi_FunctionName
(
   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_FunctionName 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

Author
28 Aug 2006 4:39 AM
Mattias Sjögren
>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.
Author
30 Aug 2006 2:59 AM
penguin
Mattias,

It works perfectly. Thanks a lot.

^_^

alex


Show quoteHide quote
"Mattias Sjogren" <mattias.dont.want.spam@mvps.org> wrote in message
news:eb$I4ulyGHA.3428@TK2MSFTNGP02.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.