Solved

C string function.

Posted on 2011-09-16
2
338 Views
Last Modified: 2012-05-12
Hi experts!

I need a little help with C string function. Look my code:

BSTR CCPlayCtrl::sErrMsgAdv(long lCard)
{
      CString strResult;
      LPCTSTR sPicFinal;
    BSTR msErrorAdv[16];

   msErrorAdv[lCard]=_T("File is invalid format”); //This works
    msErrorAdv[lCard]=_T("File" & sPicFinal & " is invalid format!"); //HERE PRODUCE ERROR, how to join these 3 texts? I may change type of BSTR msErrorAdv[16] but it should be able to full CString.

    strResult.Format( _T( "%s"),msErrorAdv[lCard]);
   return strResult.AllocSysString();

}
0
Comment
Question by:dvplayltd
[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
2 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 36549538
Hi dvplayltd,

you cannot simply concatenate C-style strings (since they are just pointers to characters, not something string objects.

The first one is working because the string on the right side is even just a char pointer.

Easiest IMO would be to use CString instead of BSTR, i.e.:
      CString strResult;
   LPCTSTR sPicFinal; // this isn't initialized!!!
   CString msErrorAdv[16];

//   msErrorAdv[lCard]=_T("File is invalid format”); //This works
   msErrorAdv[lCard].Format( _T("File %s is invalid format!"), sPicFinal );

   strResult.Format( _T( "%s"),msErrorAdv[lCard]);
   return strResult.AllocSysString();

Open in new window

Further the code as you posted will produce nonsense since sPicFinal isn't initialized.

Hope that helps,

ZOPPO
0
 

Author Closing Comment

by:dvplayltd
ID: 36549647
10x. I put it in code, it work

P.S: Of course, I will init variable - I put it here just to be more clear. All my real use is much more complex, I post here code which is only relative to question,
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

729 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