×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

string data to CString

string data to CString

string data to CString

(OP)
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)
 

RE: string data to CString

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.

 

RE: string data to CString

(OP)
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)
 

RE: string data to CString

Try

CODE

...Format(....(wchar_t*)feedback_name)
Class _bstr_t objects are not ordinal pointers to anything but there is a conversion from _bstr_t to encapsulated data pointer of BSTR type. No implicit conversion for Format(*,...) 2nd and so on arguments.
See
http://msdn.microsoft.com/en-us/library/zthfhkd6(v=vs.80).aspx
 

RE: string data to CString

(OP)
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:

Quote:


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)
 

RE: string data to CString

(OP)
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:  http://msdn.microsoft.com/en-us/library/aa314327%28v=vs.60%29.aspx
 

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close