Solved

C string function.

Posted on 2011-09-16
2
336 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

Technology Partners: 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

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

696 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