Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

wcslen() and SysStringLen()

444 views
Skip to first unread message

Ramesh M.

unread,
Aug 3, 2000, 3:00:00 AM8/3/00
to

Hi,
Is there any difference between wcslen() and SysStringLen() fn.
Sometimes, SysStringLen() returns 0 when wcslen() returns the proper length
for the same string.

Regards,
Ramesh M.

David Lowndes

unread,
Aug 3, 2000, 3:00:00 AM8/3/00
to

>Is there any difference between wcslen() and SysStringLen() fn.
>Sometimes, SysStringLen() returns 0 when wcslen() returns the proper length
>for the same string.

The Sysxxxx functions are specifically for BSTRs not wide character
strings (they're not the same). A BSTR has its allocated size stored
before the string itself, wcslen will be counting the characters to
the first NULL.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.

Ramesh M.

unread,
Aug 4, 2000, 3:00:00 AM8/4/00
to

What does the following statement mean?

"BSTR has its allocated size stored before the string itself"
When I saw the memory of the BSTR variable, it has shown only the characters
of the string.
Where will the length be actually stored in the memory?

Thanks,
Ramesh M.

David Lowndes <dav...@mvps.org> wrote in message
news:uq4josg4bjstn6he0...@4ax.com...

Andrew E. Walldorff

unread,
Aug 4, 2000, 3:00:00 AM8/4/00
to
See inline...

Ramesh M. <Rame...@VeriFone.com> wrote in message
news:eyOEYfg$$GA.293@cppssbbsa04...


>
> What does the following statement mean?
> "BSTR has its allocated size stored before the string itself"
> When I saw the memory of the BSTR variable, it has shown only the
characters
> of the string.
> Where will the length be actually stored in the memory?
>

in the 4 bytes prior to the string...
For example, concider the following
BSTR tmp = SysAllocString( L"123" );

tmp will appear to have the contents 0x31 0x00 0x32 0x00 0x33 0x00, but
actually 10 bytes were allocated and if you back up in memory, you will find
it is preceded by 0x06 0x00 0x00 0x00.

> Thanks,
> Ramesh M.
>
> David Lowndes <dav...@mvps.org> wrote in message
> news:uq4josg4bjstn6he0...@4ax.com...
> > >Is there any difference between wcslen() and SysStringLen() fn.
> > >Sometimes, SysStringLen() returns 0 when wcslen() returns the proper
> length
> > >for the same string.
> >
> > The Sysxxxx functions are specifically for BSTRs not wide character
> > strings (they're not the same). A BSTR has its allocated size stored
> > before the string itself, wcslen will be counting the characters to
> > the first NULL.
> >
> > Dave
> > --

[snip]

in addition, it is not required for BSTRs to be NULL terminated. Using
wcslen on BSTRs can lead to problems....

David Lowndes

unread,
Aug 4, 2000, 3:00:00 AM8/4/00
to

>What does the following statement mean?

I think Andrew's reply explains the situation as well as I could.

Ramesh M.

unread,
Aug 7, 2000, 3:00:00 AM8/7/00
to
I got it clear.

Thanks a lot.
Ramesh

Andrew E. Walldorff <andy.wa...@daytonrcsREMOVE.com> wrote in message
news:398ab...@nebula.superior.net...


> See inline...
>
> Ramesh M. <Rame...@VeriFone.com> wrote in message
> news:eyOEYfg$$GA.293@cppssbbsa04...
> >

> > What does the following statement mean?

0 new messages