?
Solved

C string function.

Posted on 2011-09-16
2
Medium Priority
?
341 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 opening and reading files 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.
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

762 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