Well a VB string is stored as a BSTR, if you would use VarPtr on a VB String you would get the address of the BSTR, which is a pointer to a pointer of the string. The StrPtr however will get the address of the first Unicode character in the string.
The origional pointer (the pointer that points to the pointer that points to the characters, hmm... Pointers to Pointers are confusing) doesn't change. However if you assign a new value to the string a new string is created and the StrPtr in the string is changed to point to that location. The reason your StrPtr is changing is because you constantly give it a new value (which happens to be exactly the same text, but that string is recreated in every loop turn) inside the loop.
I drawed a simple image for you that probably explains this a lot better.
So I should never rely on StrPtr for address of any string. Instead I should use VarPtr to get address of any variable - whether string or not.
EDIT: Uuhh.. I cant rate ur post!! It says - You must spread some Reputation around before giving it to Joacim Andersson again.
Nevertheless this was very helpful.
Pradeep
Last edited by Pradeep1210; Jun 11th, 2005 at 03:30 PM.
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering