SHFileOperation With List Boxes

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 would appreciate any help.
Last edited on
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.
Last edited on
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.
Last edited on
Thanks for your replies. I am sorry I was no clear on my problem. I will continue experimenting with the code and reply if I succeed.
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.
Last edited on
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
Last edited on
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:

1
2
"HELLO\0"
"HI AGAIN\0"


Will the result be:
 
"HELLOHI AGAIN\0"

?
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.
Last edited on
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.
I have succeeded!! I ended up using the ostringstream class. I am in the process of cleaning up my code, and I will post it in a while.
I'll look forward to seeing your code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
char buffer[MAX_PATH];
ZeroMemory(buffer, MAX_PATH);

ostringstream String2 (ostringstream::out);
ostringstream String1 (ostringstream::out);
int ItemCountOfList1 = SendDlgItemMessage(MainWindowHWND, IDC_LIST1, LB_GETCOUNT, 0, 0);
int ItemCountOfList2 = SendDlgItemMessage(MainWindowHWND, IDC_LIST2, LB_GETCOUNT, 0, 0);

char* List1Strings;
char* List2Strings;
				
for(int i = 0; ItemCountOfList1 > i; i++)
{
	ZeroMemory(buffer, MAX_PATH);
	SendDlgItemMessage(MainWindowHWND, IDC_LIST1, LB_GETTEXT, i, (LPARAM)buffer);
	String1 << buffer << ends;
}
String1 << ends << ends;
List1Strings = (char*)String1.str().c_str();

for(int i = 0; ItemCountOfList2 > i; i++)
{
	ZeroMemory(buffer, MAX_PATH);
	SendDlgItemMessage(MainWindowHWND, IDC_LIST2, LB_GETTEXT, i, (LPARAM)buffer);
	String2 << buffer << ends;
}
String2 << ends << ends;
List2Strings = (char*)String2.str().c_str();

FileOp.pFrom = List1Strings;
FileOp.pTo = List2Strings;

SHFileOperation(&FileOp);
Sigh.... Just compiled this code and it didn't work, oddly enough it was working just yesterday.

This is proving to be way to much of a hassle. I am going to attempt to use the more flexible IFileOperation.

I am in the process of writing a Win32 Wrapper Class, so this will be postponed.
Last edited on
Topic archived. No new replies allowed.