Solved

Is there a size limit on _bstr_t type ?

Posted on 2004-09-09
1
1,214 Views
Last Modified: 2012-06-21
Hi,
 Consider the piece of code below:

_bstr_t test1("aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa");

_bstr_t test2("bbbbbbbbbb bbbbbbbbbb cccccccccc @@@@@@@@@@ bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb");

test1 += test2;



After the third step I expected the strings to be concatenated fully, but it doesnt work that way; the protion from ccccccc is not getting appended....any idea?

0
Comment
Question by:manoj_johar
1 Comment
 
LVL 19

Accepted Solution

by:
drichards earned 250 total points
Comment Utility
THere is a limit on the size of BSTR's, but it's at least 64K, and that was in 16 bit Windows.  The length is stored in a DWORD now, so if they let you use the whole thing, it's like 4 billion characters.  Much bigger than what you've got.

Anyway, try this code and look at things in the debugger.  I just added some length calculations.  When I run your code, I get the correct result.  If I run this modified version, I get "test1: 109, test2: 109, test1+test2: 218".

    _bstr_t test1("aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa");
    UINT l1 = ::SysStringLen(test1);

    _bstr_t test2("bbbbbbbbbb bbbbbbbbbb cccccccccc @@@@@@@@@@ bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb");
    UINT l2 = ::SysStringLen(test2);

    test1 += test2;
    UINT l3 = ::SysStringLen(test1);
    std::cout << "test1: " << l1 << ", test2: " << l2 << ", test1+test2: " << l3 << std::endl;

What do you get?
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now