Already I see a whole host of problems coming out of the woodwork.
No wonder you're getting a myriad of obscure effects.
Essentially, you've been accumulating bugs without realising it. Now you have a bug-ridden large program and it's reached a critical mass where any attempt to add new code or fix a bug merely shows up another bug.
Here are some of the problems
> szFileName++
This was pointing at some allocated memory, but it isn't any more.
When you get around to free(szFileName) , you've introduced a bug into your memory allocator.
> strcat("\\\\JDEDEP\\B7333\\MEDIAOBJ\\TEXT\\", szFileName)
String constants are supposed to be read-only, yet you're trying to append data to it. On real operating systems, this would cause an immediate segmentation fault.
On your machine, it just roams through memory getting longer and longer,
so "\\\\JDEDEP\\B7333\\MEDIAOBJ\\TEXT\\"
becomes "\\\\JDEDEP\\B7333\\MEDIAOBJ\\TEXT\\foo"
becomes "\\\\JDEDEP\\B7333\\MEDIAOBJ\\TEXT\\foofoo"
becomes "\\\\JDEDEP\\B7333\\MEDIAOBJ\\TEXT\\foofoofoo" and so on until it eventually trashes some other memory.
String constants are initialised only ONCE (when the program is loaded). If you mess with them, they're changed for good. They're not automatically reset every time the line of code which refers to them is executed, so if your "Hello" has been trashed into "World" by the time you come to copy it, then "World" is what you'll get, no matter what the source code says.
So even though you may be doing strncpy(szQName, "Text", 20); , because "Text" is stored in the same kind of memory as the string you're abusing with strcat, you're going to end up with something completely different.
If this bug-rate is replicated in the rest of your large program, I'd be shocked that you got this far TBH.
Personally, given your use of strcat, and general pointer abuse, I would be recommending you re-learn C.
> I'm casting the LPSTR 'cuz I saw some other APIs doing the same.
Bad idea. Indiscriminate casting reduces the ability of the compiler to warn you when you're doing something wrong. If your code is correct, then you shouldn't need to cast it.