I have made a mistake in CString code in the past which stopped CStrings working correctly when passed as parameters. Your problem might be completely different, but I will explain here what I did to cause the problem, as it might help someone.
My CString contained a directory name. In order to clean it up a little, I checked if the last character was '\', and if so I replaced it with '\0' by directly overwriting the character inside the CString.
That probably somehow destroyed the integrity of the CString by creating a mismatch between the length of the string as measured by things like strlen(), and the actual size of the buffer. My explanation of the problem might be not be correct, but it basically boiled down to me corrupting the integrity of the CString, I assume.
I fixed my problem by replacing my statement with something like
dirname=dirname.Left(dirname.GetLength()-1);
I am writing this from memory and don't use the functions often, so forgive me if I have remembered a function name incorreclty. Anyway, my recommendation is not to write null characters into the middle of a CString to shorten it, and to look for that (among other things) if a problem occurs with CStrings as parameters.
Ah yes, I think the problem might be the reverse of yours. If you shorten a string by overwriting a character then maybe GetLength() will return the old value, which is larger than than you might expect.
My actual problem was that dir + "\" + filename was not working. I suppose it was concatentating strings containing a null and that the final value was just the directory part, as that is where the null had been added.