Click here to Skip to main content
15,911,132 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: associating static fields with edit fields Pin
Christian Graus1-Aug-05 14:11
protectorChristian Graus1-Aug-05 14:11 
GeneralRe: associating static fields with edit fields Pin
Jose Lamas Rios1-Aug-05 15:32
Jose Lamas Rios1-Aug-05 15:32 
GeneralCString to LPCTSTR Pin
jerome_data1-Aug-05 13:21
jerome_data1-Aug-05 13:21 
GeneralRe: CString to LPCTSTR Pin
Christian Graus1-Aug-05 13:24
protectorChristian Graus1-Aug-05 13:24 
GeneralRe: CString to LPCTSTR Pin
jerome_data1-Aug-05 13:40
jerome_data1-Aug-05 13:40 
GeneralRe: CString to LPCTSTR Pin
Tom Archer1-Aug-05 13:59
Tom Archer1-Aug-05 13:59 
GeneralRe: CString to LPCTSTR Pin
jerome_data1-Aug-05 14:05
jerome_data1-Aug-05 14:05 
GeneralRe: CString to LPCTSTR Pin
Jose Lamas Rios1-Aug-05 16:12
Jose Lamas Rios1-Aug-05 16:12 
jerome_data wrote:
How to convert CString to LPCTSTR.

CString already converts automatically to LPCTSTR (through a cast operator). You don't need to do anything special.

jerome_data wrote:
But pFromFolder don't works with type cast (LPCTSTR)CString

What exactly do you mean? What's your code and what's the error?

The following fragment should compile and run as expected:
   CString sFromFolder = "C:\\directory\\subdirectory";
   CString sToFolder = "C:\\directory\\OtherSubdirectory";
   if (!CDialogMaintenance::CopyFolder(sFromFolder, sToFolder))
   {
      // handle error;
   }

[UPDATE]
If that doesn't work, maybe you have wrong definitions for Unicode/MBCS? You should have one of the following combinations:

a) Unicode project: UNICODE defined, _UNICODE defined, _MBCS not defined
b) MBCS project: UNICODE not defined, _UNICODE not defined, _MBCS defined
c) No setting: UNICODE not defined, _UNICODE not defined, _MBCS not defined

Any other combination may cause problems.
[END UPDATE]

That being said, the documentation for SHFILEOPSTRUCT[^] says the following about both pFrom
and pTo:

"Although this member is declared as a null-terminated string, it is used as a buffer to hold multiple file names. Each file name must be terminated by a single NULL character. An additional NULL character must be appended to the end of the final name to indicate the end of [pFrom or pTo]"

I suggest you modify CopyFolder to something like this:

static LPCTSTR GetBufferWithExtraNull(CString s)
{
   int len = s.GetLength();
 
   // make sure the buffer has space for an additional char
   LPCTSTR p = s.GetBuffer(len+1+1);
 
   // append the required additional NULL
   p[len+1] = '\0'
 
   // note there's no ReleaseBuffer()
   return p;
}
 
BOOL CDialogMaintenance::CopyFolder(LPCTSTR pFromFolder, LPCTSTR pToFolder)
{
   SHFILEOPSTRUCT fo = {0};
 
   fo.wFunc = FO_COPY;
 
   CString sFrom = pFromFolder;
   fo.pFrom = GetBufferWithExtraNull(sFrom);
 
   CString sTo = pToFolder;
   fo.pTo = GetBufferWithExtraNull(sTo);
 
   fo.fFlags = FOF_SILENT | FOF_NOERRORUI;
 
   return (SHFileOperation(&fo) == 0=;
}


Hope that helps,

--
jlr
http://jlamas.blogspot.com/[^]
GeneralRe: CString to LPCTSTR Pin
John M. Drescher1-Aug-05 18:48
John M. Drescher1-Aug-05 18:48 
GeneralRe: CString to LPCTSTR Pin
David Crow2-Aug-05 4:21
David Crow2-Aug-05 4:21 
Generalresize a property page Pin
alkaly1-Aug-05 13:02
alkaly1-Aug-05 13:02 
GeneralRe: resize a property page Pin
Jose Lamas Rios1-Aug-05 16:38
Jose Lamas Rios1-Aug-05 16:38 
GeneralURL in Dialog box Pin
Sridhar Sanikommu1-Aug-05 11:21
Sridhar Sanikommu1-Aug-05 11:21 
GeneralRe: URL in Dialog box Pin
Christian Graus1-Aug-05 11:52
protectorChristian Graus1-Aug-05 11:52 
GeneralRe: URL in Dialog box Pin
Anonymous1-Aug-05 12:10
Anonymous1-Aug-05 12:10 
GeneralRe: URL in Dialog box - clickety police Pin
Tom Archer1-Aug-05 13:59
Tom Archer1-Aug-05 13:59 
GeneralRe: URL in Dialog box - clickety police Pin
Sridhar Sanikommu1-Aug-05 14:32
Sridhar Sanikommu1-Aug-05 14:32 
GeneralDifferentiate Windows Pin
Ista1-Aug-05 9:32
Ista1-Aug-05 9:32 
GeneralRe: Differentiate Windows Pin
David Crow1-Aug-05 10:28
David Crow1-Aug-05 10:28 
GeneralRe: Differentiate Windows Pin
Ista1-Aug-05 10:50
Ista1-Aug-05 10:50 
GeneralRe: Differentiate Windows Pin
WoutL1-Aug-05 10:55
WoutL1-Aug-05 10:55 
GeneralRe: Differentiate Windows Pin
David Crow1-Aug-05 11:17
David Crow1-Aug-05 11:17 
GeneralRe: Differentiate Windows Pin
Ista1-Aug-05 11:50
Ista1-Aug-05 11:50 
GeneralRe: Differentiate Windows Pin
Ista1-Aug-05 13:41
Ista1-Aug-05 13:41 
GeneralRe: Differentiate Windows Pin
David Crow2-Aug-05 3:44
David Crow2-Aug-05 3:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.