Click to See Complete Forum and Search --> : pointer to a string


pueromane
November 14th, 1999, 08:49 AM
A function needs a pointer to a buffer. I have a string and how can I make a pointer to this string

senthil
November 16th, 1999, 05:21 PM
Strings in Visual Basic are stored as BSTR's. If you use the VarPtr on a variable of type String, you will get the address of the BSTR, which is a pointer to a pointer of the string. To get the address of the string buffer itself, you need to use the StrPtr function. This function returns the address of the first character of the string. Take into account that Strings are stored as UNICODE in Visual Basic.

To get the address of the first character of a String, pass the String variable to the StrPtr function.

Example:


Dim lngCharAddress as Long
Dim strMyVariable as String
strMyVariable = "Some String"
lngCharAddress = StrPtr(strMyVariable)


You can use this function when you need to pass a pointer to a UNIOCODE string to an API call.

Mikesc
November 17th, 1999, 08:51 AM
Can't you just create a buffer with the string function and then pass it ByVal?