• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 606
  • Last Modified:

Simple String Concat Question

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,
1 Solution
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.
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now