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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string data to CString

Status
Not open for further replies.

bkelly13

Programmer
Aug 31, 2006
98
US
VS 2008, Windows XP Pro, novice VS user.
A vendor supplied API has as its input a string formatted as:
Code:
their_function( _bstr_t feedback feedback_name )

When an error is detected I need to show the argument. I try to put the data in a CString as follows:
Code:
CString t_show.Format( L"bad parameter is %s", feedback_name );
I use a message box to show the data but it does not display. In the debugger t_show contains:
Code:
"bad parameter is xx"
except replace the xx with two little squares representing un printable data such as displayed when the string contains "\n"
What do I need to change to get the text of feedback_name into t_show?
Please excuse typos as I cannot copy paste into this forum.


We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 
Try
Code:
CString t_show.Format( L"bad parameter is %1", feedback_name );
CStrings use positional parameters so you can do things like
Code:
CString usdate.Format (L"%2/%1/%3", dd, mm, yy);
CString eurodate.Format (L"%1/%2/%3", dd, mm, yy);
CString chindate.Format (L"%3/%2/%1", dd, mm, yy);
Basically the code remains the same but the format text, which can be read in from a language file, changes.

 
Well that was unexpected. I have used (L" text %d text", number ) in several places and it displayed as expected. Just the same I will try your suggestion tommorow.
Thanks for taking the time to post.

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 
This is not working out so well. Inside a function call an argument is
Code:
function_x( ..., CString feedback_name );
In the debugger I can see that feedback_name contains valid text. Another function is called and it throws an exception. The problem is that the name in the argument does not match something else, somewhere else, but that doesn't matter at the moment. In the catch block is the following:
Code:
Cstring t_show;
...
t_show.Format(L"function x reports error with name %1", feedback_name );
The code is trying to build a string showing the user the feedback name that caused the problem. When that line of code, the t_show.Format is stepped over with the debugger the result is a window that pops up saying:
Debug Assertion Failed
File f:\dd\vctools\crt_bld\self_x86\crt\src\outputc
Line 2293
The quite is not exact as I cannot copy paste from that computer into this one. I stepped through that and cannot make heads or tails of all the check functions that come up.

I have found the problem that causes the exception. Now I need to figure out why the code to show me the error blows up.

So, is it legal to use that Format method of a string to include another string in it as I have?





We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 
In answer to my question I have discovered that to include a CString within a CString using the Format method the included CString must be cast with LPCTSTR. The page where I found this is:

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top