I am writing a simple Win32 Application that copies files from one location to another using SHFileOperation. According to MSDN, SHFileOperation can take multiple directories for the "pTo" and "pFrom" parameters. It also says that each directory must be separated by a null terminator, and then the last directory should end with a double null terminator. I have a list box on my applications window where the user can enter strings into the list box. My problem is that I don't know how to take the strings from the list box, combine them with a null terminator in between each one, and then add a double null terminator at the end.
I was not expecting to recieve a sarcastic response like that. I am asking how to manipulate the strings so that I can insert the null terminators where needed, with an unknown number of strings in the list box. And just for future reference, I am capable of searching on MSDN.
I am clueless as to why you think that my providing links for your question is sarcastic since it SPECIFICALLY addresses your question.
Getting strings from list boxes is EXTREMELY basic, and so if you don't know how to do that, then that means you need to read about and understand at least the BASICS of list boxes.
In that vein, the first link I provided above concerns LB_GETTEXT which just happens to be the VERY THING YOU NEED in order to retrieve a string from a list box.
If you can't figure out how to use LB_GETTEXT, then all you have to do is say so.
You need to understand that I am a competent person and know how to get strings from list boxes, and I would not have posted something that could have bee solved by a simple Google search. Your response did not address my question at all. I am sorry if I was not clear about my question. I am asking how to manipulate the strings so that I can insert the null terminators where needed, with an unknown number of strings in the list box. I have read all I can find on the subject on MSDN, so providing me with links there will not help.
I can't read your mind. Here is exactly what you wrote --
"My problem is that I don't know how to take the strings from the list box, combine them with a null terminator in between each one, and then add a double null terminator at the end."
It is not unusual to interpret that as meaning that you don't how to get a string from a list box since you stated -- "...I don't know how to take the strings from the list box..."
With regard to string manipulation, you'll have to be more clear. For example, you can use strlen() to obtain the length of the string that you retrive from the list box and just add a null terminator to it. Like this --
1 2
int iLen = strlen(myString);
myString[iLen]=0;
If that's not what you're looking for, you'll have to be more specific.
Also, if you're trying to put a null terminator between each string from the list box into one single string, and yet still have a null terminator between each string, then I don't know how you would do that.
This is proving to be a much more complex thing than I had originally anticipated. ANY suggestions would be GREATLY appreciated.
What I need to do is combine all strings from a list box, and then have a null terminator in between each string. The string should be double null terminated. This string will be passed to the pTo or pFrom member of the SHFILEOPSTRUCT that I have declared.
Hi,
Not sure if this would fix your problem but as I see it your trying to concatenate a number of strings from a list box and put null terminators between them?
If so could you not do something similar to the following:
Get first string from box
add null terminator to end (using code from above)
concatenate that with a result string (currently empty)(strcat?)
and repeat for all items in the list box?
Oh and add you extra null terminator when your done
Thanks for your reply. Also, correct me if I'm wrong, but doesn't strcat replace the null terminator on the result string with the first character in the source string?
For example, if I use strcat to cat these two strings together:
If I understand what you really want to do, then it is truly problematic. Every string function that I know (and I am sure that there are MANY that I am not very familiar with), nevertheless, every string function that I am aware of accepts a NULL character as the terminator of the string.
Thus, you are either going to have to find a string coordinator that can override this, OR, and this is just a maybe, because I don't know what outcome you need, but you MIGHT, POSSIBLY could do something like this...
To wit: place two nonsense characters at the end of each string throughout the whole strcat() process so that you end up with one universal string. Then you could iterate back through that string as you were processing it in the OUTPUT.
That will only work, if it works at all, if your actual output doesn't require the string to be a whole cloth string.
If that won't help you, then you may have to resort to some type of Assembly routine to accomplish what you want.
In short, this is way over my head. Somebody with a great deal more expertise will have to find a solution on this one.
And also, there are going to be multiple NULL terminators in the string, so the strcat function will insert the string at the first NULL terminator it finds. This will mess up the formatting of the string.
I am considering writing my own strcat function at this point.
I seriously hope I don't have to resort to Assembly.