|
From: Guillermo G. <ggu...@ma...> - 2005-05-18 15:26:12
|
yes you are correct, everything works perfect now. I also have a much = better understanding of strings and "\0" as well as the string = manipulation functions. thank you soooooooooooooooo much for your help. P.S. sorry, didn't mean to not include the list. The whole "Reply" vs. = "Reply to All" thing is something I still can't get used to. I am = spoiled by other mailing lists that send to the list's address when you = hit reply instead of the individual's email address. -----Original Message----- From: Per Westermark [mailto:pw...@ia...] Sent: Tuesday, May 17, 2005 9:13 PM To: Guillermo Gutierrez Subject: RE: FW: [Dev-C++] Win32 Shell API Once more: strlen() or any other strxxx() function can NOT be used when processing strings containing \0 in the middle. It is impossible to do strlen(SrcPath) and get more than the length of = the FIRST file name inserted into the array! The '\0' separator between the file names will stop strlen() early! Normal printout functions can NOT display the contents of the following file names, even if they are correctly stored in the array. Even if SrcPath is non-printable, this code DO work! char SrcPath[1000],*p; p =3D SrcPath; strcpy(p,"c:/src/1.txt"); p +=3D strlen(p)+1; // Step past first file name + one '\0' strcpy(p,"c:/src/2.txt"); p +=3D strlen(p)+1; // Step past second file name + one '\0' strcpy(p,"c:/src/3.txt"); p +=3D strlen(p)+1; // Step past third file name + one '\0' strcpy(p,""); // Insert an extra '\0' as empty filename ... op.pFrom =3D SrcPath; If you build file names in two steps, the above code could instead look like: p =3D SrcPath; strcpy(p,"c:/src/"); // Add path strcat(p,"1.txt"); // Add name part p +=3D strlen(p)+1; // Step past fully qualified file name and '\0' strcpy(p,"c:/src/"); strcat(p,"2.txt"); p +=3D strlen(p)+1; strcpy(p,"c:/src/"); strcat(p,"3.txt"); p +=3D strlen(p)+1; strcpy(p,""); ... op.pFrom =3D SrcPath; or you can even write: p =3D SrcPath; sprintf(p,"c:/src/%d.txt",1); p +=3D strlen(p)+1; sprintf(p,"c:/src/%d.txt",2); p +=3D strlen(p)+1; sprintf(p,"c:/src/%d.txt",3); p +=3D strlen(p)+1; strcpy(p,""); As you can see, any number of different methods may be used to create = the source array. It's just a question of understanding how it works. The important part - that I haven't bothered to discuss - is of course = to keep track of the total size consumed of SrcPath, to make sure you don't get a buffer overflow. The above constructs consumes 1+(p-SrcPath) characters. Once more. Do = NOT think strlen(SrcPath) will help you! To avoid buffer overflows, strncpy, strnprintf or strlen of the individual file names might be used while constantly keeping track of remaining space in the buffer to make sure bad things don't happen! By the way - now we are off the mailing list again! /Per W On Tue, 17 May 2005, Guillermo Gutierrez wrote: > forget the error 6, that was an error in some other area. for some = reason only the first string (LP4) is being placed into SrcPath/SrcPtr = so only one file is being copied. > > -----Original Message----- > From: Guillermo Gutierrez > Sent: Tuesday, May 17, 2005 5:32 PM > To: 'Per Westermark' > Subject: RE: FW: [Dev-C++] Win32 Shell API > > > I am still receiving the error code 6 from windows. I tried changing = the code that sets the source path to: > > char SrcPath[20000]; > char* SrcPtr =3D SrcPath; > > strcpy ( SrcPtr, LP4 ); > SrcPtr +=3D strlen( SrcPtr ) + 1; > strcpy ( SrcPtr, SFA ); > SrcPtr +=3D strlen( SrcPtr ) + 1; > strcpy ( SrcPtr, "" ); > > and the error still happens. I suspect that maybe "strlen ( SrcPtr ) + = 1" could/should be "strlen ( SrcPath) + 1"? > > > -----Original Message----- > From: Per Westermark [mailto:pw...@ia...] > Sent: Tuesday, May 17, 2005 4:30 PM > To: Guillermo Gutierrez > Cc: dev...@li... > Subject: RE: FW: [Dev-C++] Win32 Shell API > > > That is your problem. > > You simply can not use strcat to concatenate a "\0" since it breaks at = the > \0 in the string. > > p =3D SrcPath; > strcpy(p,LP4); > p +=3D strlen(p)+1; // skip # of inserted chars + the '\0'; > strcpy(p,SFA); > p +=3D strlen(p)+1; // "- > strcpy(p,""); // just writes the final '\0' > > And of course, you can not use std::cout to emit a char* or char[] = that > contains '\0' in the middle... > > /Per W > > On Tue, 17 May 2005, Guillermo Gutierrez wrote: > > > I am using a char SrcPath[20000] variable to hold the name (yes, the = full string gets close to being that long.) > > > > I fill the array like this: > > > > //LP4 is a variable that holds the source path + filename (lp4.exe) > > //SFA - (same as above, source path + "mssfa.exe") > > > > strcpy ( SrcPath, LP4 ); > > strcat ( SrcPath, "\0"); > > strcat ( SrcPath, SFA ); > > strcat ( SrcPath, "\0\0" ); > > std::cout << "SrcPath: " << SrcPath << endl; > > > > unfortunately the output of "cout << SrcPath" shows both of the = paths as one that is what is causing the app to think of it as one huge = path for a file rather than 2 paths/files. |