-
Hello!
It's me again and now I have another question for one of you.
How can I combine 2 (or more) strings (like in VB: str1 = str2 & str3)?
I tried with + operator but I allways get an error: "error C2110: cannot add two pointers"
Here's the code:
Code:
LPTSTR tcCurDir;
GetCurrentDirectory(MAX_PATH, tcCurDir);
cCurDir = tcCurDir + "\\bla.exe";
ShellExecute(NULL, "open", tcCurDir, NULL,NULL,SW_SHOWDEFAULT);
-
Damn, I got a BUG!
The right code is this one:
Code:
LPTSTR tcCurDir;
GetCurrentDirectory(MAX_PATH, tcCurDir);
tcCurDir = tcCurDir + "\\bla.exe";
ShellExecute(NULL, "open", tcCurDir, NULL,NULL,SW_SHOWDEFAULT);
-
I think this will work.
Code:
TCHAR curdir[256];
GetCurrentDirectory(MAX_PATH,curdir);
char fl[9]={"\\bla.exe"};
strcat(curdir,fl);
The Path and filename You want is stored in curdir.
-
Nope. You can't. In C++, your basic string isn't a string. It's an array, terminated with a '\0'.
To add two strings, you make another buffer that's big enough for both, then copy them in. Also, you need to use the _T macro:
Code:
TCHAR ptcCurDir[MAX_PATH];
TCHAR *ptcFile = _T("\\blah.exe");
GetCurrentDirectory(MAX_PATH, ptcCurDir);
ptcFile = new TCHAR[_tcslen(ptcCurDir) + _tcslen(ptcFile) + 1];
_tcscpy(ptcFile, ptcCurDir);
_tcscpy(ptcFile+_tcslen(ptcCurDir), ptcFile);
ptcFile[_tcslen(ptcCurDir) + _tcslen(ptcFile)] = 0;
...or similar. I can't test this under NT, but that's the basic idea.
-
Um...Vlatko - you've got your Unicode stuff in a twist. You can't mix & match like that...
Zvonko - you can actually get round this by using the STL string class (file string must be included, and a using namespace std; somewhere in your headers)
Code:
TCHAR ptcCurDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH, ptcCurDir);
basic_string<TCHAR> sFinalPath = ptcCurDir;
sFinalPath += _T("\\blah.exe");
...pass sFinalPath.c_str() in place of an LPTSTR argument.
-
Wow, guys!
Don't know for your opinion, but you RULE!
Where do you get this much knowledge?
I have some (actually pretty much) knowledge about VB - I'm programming with it now over 2 years.
I know that I've just started VC++ and I don't know much about programming in it, but it seems you have all that knowledge in your little finger. ;)
As I already told you I'm rookie (very green rookie) and don't resend me if I'll be asking stupid questions... :)
-
Code:
Where do you get this much knowledge?
...how does doing it for 8 years sound?
I don't resent people who know less than me, because I was once in that stage, and needing help myself.
Seriously, though, once you've got pointers, arrays, and data type sizes well and truly sorted, you've arrived :).