?
Solved

Simple String Concat Question

Posted on 2003-02-25
7
Medium Priority
?
476 Views
Last Modified: 2012-08-13
LPCTSTR m_pszExeName; // I have this, its the exe name

char buf[128]; // I want to add this onto it it has a name in it
------------------

I want to concat a char buffer(up to 128 bytes) onto an LPCTSTR. What is the easiest way? The end reslt needs to be a concatanated LPCTSTR to use for CreateSeamphore.

HANDLE hSem = CreateSemaphore(NULL, 1, 1, MyConcatLPCTSTRgoesHere);


Thanks for the help,
Doug
0
Comment
Question by:DougC
[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
  • 4
  • 3
7 Comments
 
LVL 1

Accepted Solution

by:
vadik earned 80 total points
ID: 8019244
LPCTSTR lp = "FirstStr";
TCHAR buf[128] = "SecondStr"; // I think is better using
                             // TCHAR instead of char.
_tcscat(&buf[0], lp);

// Do something with buf... for example
HANDLE hSem = CreateSemaphore(NULL, 1, 1, &buf[0]);



0
 
LVL 6

Expert Comment

by:gj62
ID: 8020217
vadik -

Just a quick note - the order of your strings I think is backward.  

Buf would actually equal "SecondStrFirstStr" after concatenation.

I think he wants _tcscat(lp, buf);
0
 
LVL 1

Expert Comment

by:vadik
ID: 8020325
Just I thought that it's not good to change LPCTSTR because this is pointer to const. But this is only my oppinion.
0
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.

 
LVL 1

Expert Comment

by:vadik
ID: 8020382
Just I thought that it's not good to change LPCTSTR because this is pointer to const. But this is only my oppinion.
0
 
LVL 6

Expert Comment

by:gj62
ID: 8020487
You are right, though MSFT shows examples of doing exactly that - anyhow, he'd be better off creating a new object and storing the concatenated string there...

e.g.

CString params;
params = lp + buf;

would probably be easiest...
0
 
LVL 1

Expert Comment

by:vadik
ID: 8020733
If you are using MFC :)
0
 
LVL 6

Expert Comment

by:gj62
ID: 8020945
True - bad assumption...
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

770 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