Back slashes '\' and SHGetSpecialFolderPath
-
It's not my application actually.. There might be several applications whose "theApp" I don't have.
The example I posted recently was previously developed for the std::string class. If you are just using CString objects wrapping is even easier:
CString test;
test += "\"";
test += path;
test += "\"";
test.Replace("\\", "\\\\");Regards
We can do no great things, only small things with great love. - Mother Theresa
-
The example I posted recently was previously developed for the std::string class. If you are just using CString objects wrapping is even easier:
CString test;
test += "\"";
test += path;
test += "\"";
test.Replace("\\", "\\\\");Regards
We can do no great things, only small things with great love. - Mother Theresa
-
I do not want to put quotation marks to both ends of the text. I want to convert a string (i.e. CString) like C:\Program Files to C:\\Program Files - which is doubling the back slashes... Regards
Ok, that's a one-liner :) If you have
CString test("C:\\Program Files");
just call
test.Replace("\\", "\\\\");
Regards
We can do no great things, only small things with great love. - Mother Theresa
-
Ok, that's a one-liner :) If you have
CString test("C:\\Program Files");
just call
test.Replace("\\", "\\\\");
Regards
We can do no great things, only small things with great love. - Mother Theresa
When the string has a backslash it acts differently. I know that to add a quotation mark, you need a backslash in front of it. CString::Insert and CString::operator + act different when there is a backslash in the CString object. I'm sorry to say that I could not get a result with the code you sent either. Regards -- modified at 7:48 Monday 29th August, 2005
-
When the string has a backslash it acts differently. I know that to add a quotation mark, you need a backslash in front of it. CString::Insert and CString::operator + act different when there is a backslash in the CString object. I'm sorry to say that I could not get a result with the code you sent either. Regards -- modified at 7:48 Monday 29th August, 2005
Ok, please give me a moment...
We can do no great things, only small things with great love. - Mother Theresa
-
When the string has a backslash it acts differently. I know that to add a quotation mark, you need a backslash in front of it. CString::Insert and CString::operator + act different when there is a backslash in the CString object. I'm sorry to say that I could not get a result with the code you sent either. Regards -- modified at 7:48 Monday 29th August, 2005
I'm a bit confused... I can't find a difference between CString::Insert and CString::operator+ I sent you an email with the example I have coded...
We can do no great things, only small things with great love. - Mother Theresa
-
I'm a bit confused... I can't find a difference between CString::Insert and CString::operator+ I sent you an email with the example I have coded...
We can do no great things, only small things with great love. - Mother Theresa
-
I see that it works with your code, but not with the code I have, which is similar to yours (see my initial message). I don't understand. Thanks and regards
Hi, this time I implemented your posted code back-to-back and got the same error. The problem is related to the CString::GetBuffer() method. CString::GetBufferSetLength() should fix the problem. But I would prefer:
char buffer[_MAX_PATH];
SHGetSpecialFolderPath(NULL, buffer, CSIDL_PROGRAM_FILES, FALSE);
CString PFPath(buffer);
Regards
We can do no great things, only small things with great love. - Mother Theresa
-
Hi, this time I implemented your posted code back-to-back and got the same error. The problem is related to the CString::GetBuffer() method. CString::GetBufferSetLength() should fix the problem. But I would prefer:
char buffer[_MAX_PATH];
SHGetSpecialFolderPath(NULL, buffer, CSIDL_PROGRAM_FILES, FALSE);
CString PFPath(buffer);
Regards
We can do no great things, only small things with great love. - Mother Theresa
-
Hi, I have a problem with using a path. I have to obtain the program files' path programatically, therefore I use this function.
// Get Program Files Path
CString PFPath;
SHGetSpecialFolderPath(NULL,PFPath.GetBuffer(_MAX_PATH),CSIDL_PROGRAM_FILES, FALSE);
MessageBox(PFPath);and the message box says: C:\Program Files I need to add something at the end of this string and then i try to use it in another function which needs the paths in double back slashes like: "C:\\Program Files" Then I try to do a conversion in PFPath in order to double the backslashes to change from "C:\Program Files" to "C:\Program Files"
// double
int i=0;
i = PFPath.Find("\\",i);
while( i>-1 )
{
CString found;
found.Format("Backslash found at index: %d",i);
MessageBox(found);
//Insert a \ in front of the found one to double it
PFPath.Insert(i,(CString)"\\");
MessageBox(PFPath);
//Get the next one
i += 2;
i = PFPath.Find("\\",i);
}
if(i==-1)
MessageBox("No more backslashes");
MessageBox(PFPath);The message box output of this path is: Backslash found at index: 2 \ No more backslashes \ As seen, the insert function turned the whole string into a single backslash instead of inserting one.
// extend the path
CString WholePath = PFPath + (CString)"\\some_folder\\myfile.exe";
SHELLEXECUTEINFO shellInfo;
...
shellInfo.lpFile = WholePath;
::ShellExecuteEx(&shellInfo);The conversion cannot be done properly, and shellInfo.lpFile needs double slashes. Therefore ShellExecuteEx cannot receive the path. I have also tried the '\' conversion issue with
CString::Replace
;CString::left, CString::Right
and concetanation with operator+
. Now I'm almost convinced that it is not possible to do it with the CString class. :confused: Is there any other way to convert the '\' to '\\'? Regards and thanks in advance, Caykahve -- modified at 5:49 Monday 29th August, 2005caykahve wrote: and the message box says: C:\Program Files I need to add something at the end of this string and then i try to use it in another function which needs the paths in double back slashes like: "C:\\Program Files" Then I try to do a conversion in PFPath in order to double the backslashes to change from "C:\Program Files" to "C:\Program Files" You don't actually need any conversion. The double back slash is needed only when you are writing a string literal in your code. That's because the back slash is a escape character (used in combinations like \t, \r and \n, to represent a tab, carrier return, and line feed characters), when what you want is an actual back slash character, you need to type it twice. However, the double back slash pair represents one (single) back slash character in memory. -- jlr http://jlamas.blogspot.com/[^]