Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sting function for API

Status
Not open for further replies.

stranger123

Programmer
Apr 16, 2006
76
GB
Hi,

When pass a string between VB and API, what is the difference by use String(255, chr(32)) and String(255, chr(0))?

Thank you in advance.
 
Big difference.

String(255, Chr(0)) is a string of 255 null (ASCII zero) characters. The null characters are the usual end of string marker. So, a string of 255 null characters is unlikely to cause string overrun.

String(255, Chr(32)) is a string of 255 spaces. It doesn't necessarily have an end of string marker, as expected by a lot API calls. To be safe, one should pass a buffer that is null terminated.


Cassie
PIII-500Mhz-128MB
Win98SE-VB6SP5
 
Thank you.
I have just tested it is not working by use
String(254,chr(32)) & chr(0)
 
If you post your code (stripping out the irrelevant parts), we might be able to help. Normally the APIs use null terminated strings.
 
>To be safe, one should pass a buffer that is null terminated.

Well, that was certainly the case in older versions of VB. However, VB6 uses BSTRs, which are already null-terminated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top