Help Experts...CString to LPCSTR conversion
-
here's the solution.. myprogram() { CString str; // //how to convert this str to LPCSTR // myfunc(LPCSTR(str))---??? } myfunc(LPCSTR str) { .... .... ... } ___________________________ When a thing is new, people say, "It's not true." Later, when its truth becomes obvious, people say, "It's not important." Finally, when its importance cannot be denied, people say, "Well, it's not new."
hi, my exact code is: myprogram() { CString EZBuf; EZBuf.Format("%sEZBuf",HardDiskLetters[iCounter]); //where HardDiskLetters[iCounter] = c:\\ DelTree((LPCSTR)EZBuf); } DelTree(LPCSTR path) { ... } //////////////////////////////// Deltree function is used to remove the directory I tried your method but it didnot worked. On other hand if i pass c:\EZBuf in the function then the program works fine ///////////////////////////////// Can anybody tell where the problem is ?? Rohit
-
hi, my exact code is: myprogram() { CString EZBuf; EZBuf.Format("%sEZBuf",HardDiskLetters[iCounter]); //where HardDiskLetters[iCounter] = c:\\ DelTree((LPCSTR)EZBuf); } DelTree(LPCSTR path) { ... } //////////////////////////////// Deltree function is used to remove the directory I tried your method but it didnot worked. On other hand if i pass c:\EZBuf in the function then the program works fine ///////////////////////////////// Can anybody tell where the problem is ?? Rohit
check out ur HardDiskLetters.. i sur harddisk letter is "C:" hten u need to add '\\' in ur code EZBuf.Format("%s\\EZBuf",HardDiskLetters[iCounter]); in any case, final string in 'EZBuf' should be "C:\dir_name" try it out.. Bhaskar ___________________________ When a thing is new, people say, "It's not true." Later, when its truth becomes obvious, people say, "It's not important." Finally, when its importance cannot be denied, people say, "Well, it's not new."
-
check out ur HardDiskLetters.. i sur harddisk letter is "C:" hten u need to add '\\' in ur code EZBuf.Format("%s\\EZBuf",HardDiskLetters[iCounter]); in any case, final string in 'EZBuf' should be "C:\dir_name" try it out.. Bhaskar ___________________________ When a thing is new, people say, "It's not true." Later, when its truth becomes obvious, people say, "It's not important." Finally, when its importance cannot be denied, people say, "Well, it's not new."
BhaskarBora wrote: When a thing is new, people say, "It's not true." Later, when its truth becomes obvious, people say, "It's not important." Finally, when its importance cannot be denied, people say, "Well, it's not new." LOL! True!
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi -
check out ur HardDiskLetters.. i sur harddisk letter is "C:" hten u need to add '\\' in ur code EZBuf.Format("%s\\EZBuf",HardDiskLetters[iCounter]); in any case, final string in 'EZBuf' should be "C:\dir_name" try it out.. Bhaskar ___________________________ When a thing is new, people say, "It's not true." Later, when its truth becomes obvious, people say, "It's not important." Finally, when its importance cannot be denied, people say, "Well, it's not new."
hi:doh:, I tried both ways but it didnot worked. void myfun() { CString str; str.Format("%sEZBuf",HardDiskLetters[iCounter]); DelTree(str); //doesnot works DelTree((LPCSTR)str); // doesnot works DelTree("c:\\EZBuf"); //Works } DWORD DelTree(LPCSTR pszBase) { SHFILEOPSTRUCT sFileOp; ZeroMemory(&sFileOp, sizeof(SHFILEOPSTRUCT)); sFileOp.wFunc = FO_DELETE; sFileOp.pFrom = pszBase; sFileOp.fFlags = FOF_SILENT|FOF_NOCONFIRMATION|FOF_NOERRORUI; SHFileOperation(&sFileOp) ; return 0; }
-
hi:doh:, I tried both ways but it didnot worked. void myfun() { CString str; str.Format("%sEZBuf",HardDiskLetters[iCounter]); DelTree(str); //doesnot works DelTree((LPCSTR)str); // doesnot works DelTree("c:\\EZBuf"); //Works } DWORD DelTree(LPCSTR pszBase) { SHFILEOPSTRUCT sFileOp; ZeroMemory(&sFileOp, sizeof(SHFILEOPSTRUCT)); sFileOp.wFunc = FO_DELETE; sFileOp.pFrom = pszBase; sFileOp.fFlags = FOF_SILENT|FOF_NOCONFIRMATION|FOF_NOERRORUI; SHFileOperation(&sFileOp) ; return 0; }
-
your problem is that - in 'sFileOp.pFrom' the list of names must be double null-terminated!!! with: str.Format("%sEZBuf%c",HardDiskLetters[iCounter],'\0'); your function will work fine. CC.
Great brain.. Constantin. Thanks a lot. :-D
-
Good Morning, I am developing an application in MFC VC++ Version 6.0 for Windows 2000 I need some help. How can we convert CSTring to LPCSTR I have a function in which I neet to pass LPCSTR type agument. myprogram() { CString str; // //how to convert this str to LPCSTR // myfunc(str)---??? } myfunc(LPCSTR str) { .... .... ... } Waiting for a positive response. Rohit
Hi, I think just with a casting could be enough ? CString Mystring; myfunc((LPCSTR) Mystring); If not, try this: CString MyString; myfunc(MyString.GetBuffer(0)); MyString.ReleaseBuffer(); HTH Braulio
-
Good Morning, I am developing an application in MFC VC++ Version 6.0 for Windows 2000 I need some help. How can we convert CSTring to LPCSTR I have a function in which I neet to pass LPCSTR type agument. myprogram() { CString str; // //how to convert this str to LPCSTR // myfunc(str)---??? } myfunc(LPCSTR str) { .... .... ... } Waiting for a positive response. Rohit
-
Good Morning, I am developing an application in MFC VC++ Version 6.0 for Windows 2000 I need some help. How can we convert CSTring to LPCSTR I have a function in which I neet to pass LPCSTR type agument. myprogram() { CString str; // //how to convert this str to LPCSTR // myfunc(str)---??? } myfunc(LPCSTR str) { .... .... ... } Waiting for a positive response. Rohit
It would be nice if your explanation could describe whether this error was a syntax or semantic error. From your description, most people with a good english understanding would have thought that "does not work", implies a syntax compiler error, however, from constantin's solution I can see you actually meant "does not work" in a semantic sense where the function does not operate how you expect it to. It would be great if people could do this in their questions to stop nutters like me barking up the wrong tree, racking my brains for a solution that doesn't exist :mad:. Alan.
-
It would be nice if your explanation could describe whether this error was a syntax or semantic error. From your description, most people with a good english understanding would have thought that "does not work", implies a syntax compiler error, however, from constantin's solution I can see you actually meant "does not work" in a semantic sense where the function does not operate how you expect it to. It would be great if people could do this in their questions to stop nutters like me barking up the wrong tree, racking my brains for a solution that doesn't exist :mad:. Alan.
Dear :mad:Alan, Will definately take care from now onwards, Rohit:-D