SHARE
Facebook X Pinterest WhatsApp

WRAPTRACE() – Long String Debugging Macro

I kept running into situations where, during debugging, I needed to view the contents of long strings. None of the features available in VC++ were satisfactory. The onscreen, expression, hover feature only displays one screen-width line of the variable’s contents. Also, even though an AfxMessageBox() can display thousands of characters, it doesn’t have scroll bars […]

Written By
thumbnail
CodeGuru Staff
CodeGuru Staff
Dec 21, 1998
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

I kept running into situations where, during debugging, I needed to view the contents
of long strings. None of the features available in VC++ were satisfactory. The onscreen,
expression, hover feature only displays one screen-width line of the variable’s contents.
Also, even though an AfxMessageBox() can display thousands of characters, it doesn’t have
scroll bars and is therefore limited to a viewing area of one screen (about 4,200
characters). In addition, you cannot capture text from an AfxMessageBox(). Finally, MFC’s
TRACE() debug maco is limited to dumping a maximum of 512 characters to the output window.

To provide a solution to this problem, I wrote the WRAPTRACE() macro. This handly little
debugging tool breaks down a long string into 80 character, or shorter, lines of text for
display in Developer Studio’s output window. Like TRACE(), it is only available during
debug. However, unlike TRACE(), the output from WRAPTRACE() is imited only by the 32k size
barrier of the CString class.

The source compiles and runs fine on VC++ 5.0.

CODE EXAMPLE:

CString strString = "A businessman walked into a New"
"York City bank and asked for the loan officer. He said he was going to Europe on business"
"for two weeks and needed to borrow $5,000. The loan officer said the bank would need some"
"security for such a loan. The business man then handed over the keys to a Rolls Royce that"
"was parked on the street in front of the bank. Everything checked out and the loan officer"
"accepted the car as collateral for the loan. An employee then drove the Rolls into the"
"bank's underground garage and parked it there. Two weeks later the businessman returned,"
"repaid the $5,000 plus the interest, which came to $15.41. The loan officer said,"
""We do appreciate your business and this transaction has worked out very nicely, but"
"we are a bit puzzled. While you were away we checked and found that you are a"
"multimillionaire. What puzzles us is why you would bother to borrow $5,000?" The"
"business man replied: "Where else in New York City, can I park my car securely for 2"
"weeks for only 15 bucks?"";
WRAPTRACE(strString);

OUTPUT WINDOW TEXT:

A businessman walked into a New York City bank and asked for the
loan officer.
He said he was going to Europe on business for two weeks and needed to borrow
$5,000. The loan officer said the bank would need some security for such a
loan. The business man then handed over the keys to a Rolls Royce that was
parked on the street in front of the bank. Everything checked out and the loan
officer accepted the car as collateral for the loan. An employee then drove the
Rolls into the bank's underground garage and parked it there. Two weeks later
the businessman returned, repaid the $5,000 plus the interest, which came to
$15.41. The loan officer said, "We do appreciate your business and this
transaction has worked out very nicely, but we are a bit puzzled. While you
were away we checked and found that you are a multimillionaire. What puzzles us
is why you would bother to borrow $5,000?" The business man replied: "Where
else in New York City can I park my car securely for 2 weeks for only 15 bucks?"

Because the text is sent to the output window, it can also be selected and copied
elsewhere. This is a very useful tool for debugging embedded SQL. For instance, in the
statement just before a recordset is opened, the SQL string is sent via WRAPTRACE() to the
output window. The SQL string is then selected and copied into an MS Access97 query where
it can be run and debugged. It works great!

Download source – 2 KB

Date Posted: 12/22/98

Recommended for you...

Top Plugins for Visual Studio
Enrique Stone
Feb 3, 2023
Developer News Is Coming Back to Visual Studio
Hannes DuPreez
Jan 24, 2023
GitHub Copilot Overview
Hannes DuPreez
Aug 6, 2022
Visual Studio 2022 for Mac Released
Hannes DuPreez
Jun 20, 2022
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.