Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Is there a size limit on _bstr_t type ?

Posted on 2004-09-09
1
Medium Priority
?
1,347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 19

Accepted Solution

by:
drichards earned 750 total points
ID: 12024204
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

618 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