Simple String Concat Question

Posted on 2003-02-25
Medium Priority
Last Modified: 2008-02-01
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,
Question by:DougC
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

Expert Comment

ID: 8018959
If you're using a CString or a std::string, you can just use the += operator, like:
CString str; // could also be std::string
str += "whoops"; // str = "whoops"
str += "screwedup"; // str = "whoopsscrewedup"
If you need to use a char array, strcat would do it, like:
char buf[128];
strcpy(buf, "stuff"); // buf = "stuff"
strcat(buf, "morestuff"); // buf = "stuffmorestuff"

Good luck.

Accepted Solution

PlanetCpp earned 80 total points
ID: 8019386
you might have a problem with your data type
LPCTSTR is a long pointer to a constant zero terminated TCHAR
if your saying
LPCTSTR exename; or LPCTSTR exename[128]; or any number
 your not making a char array your making an array of 128 char *'s
don't use that even though thats what createsemaphore wants
you make them as normal
char exename[MAX_PATH+130] = {""};
MAX_PATH is used for path to files cause thats the maximum windows allows for path names on that version
+130 is because ontop of the path you wanted to add 128 (extra 2 for no real reason) so in worst cxase scenario of the path being the max length your still safe.
use exename to get the path
when you pass exename to createsemephore it should go with no problem, if it doesnt then you simply cast it, you shouldnt have to do this though
but just pass as exename cause it should go with no problem.

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 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