We help IT Professionals succeed at work.

Can I use REadDirectoryChanges()?

chenwei
chenwei asked
on
I use MSVC 6.0 for programming. In my program I will use the function to watch the change of the directory. Since I don't want Unicode, I want to use the function ReadDirectoryChanges(). But as I compile the program, it shows that it can't find this function. As I open the online-help, I just find ReadDirectoryChangesW(). But this what I don't want since it's a unicode function.
Comment
Watch Question

Commented:
There is no ansicode function for ReadDirectoryChanges, the unicode function is your only choice, sorry...

Regards, Madshi.
BRONZE EXPERT

Commented:
why cant u use this unicode funktion?? r u developing for a win9x system?

Author

Commented:
I develop program for WinNT. Maybe this function is just for Win9x. The disadvantage using the function ReadDirectoryChangesW is I have to convert the unicode string to normal string. I am looking a better solvement to convert a Unicode string to a nrmal string.

Commented:
This function is only available in NT based systems. Win9x doesn't support this function.

Converting a unicode string should be fairly easy. Why not using the function WideCharToMultiByte? If that is too slow for you (I don't know why it should, directory changes occur not very often, if you compare that to the power of today's CPUs), you could easily write a little inline assembler loop, which loops through the widechar string, until it finds a 0 word, and copies the characters from the widechar string to a normal string. Should be fast as hell...

Regards, Madshi.

Author

Commented:
Yes, I do sue a while or for loop to convert the unicode string to normal strig such as:
for(int i=0, i<= legthOfUnicode; i++)
  unicodestr[i] = (char)normalstring[i];

But I just want to know if there is any better method. I've also tryed using sprintf() such as:
sprintf(normalstring, "%s", unicodestring);

But it just copy the first character. I know WideCharToMultiByte(). I am the same oppinion that it could be slow.


Commented:
Your loop should be fine. Just think of how fast the CPUs are, and your loop basically just copies some memory. This will be probably a million times faster than renaming one file. You should not be afraid of performance penalties. If you still are, why not doing a little test? Let your loop convert 1000000 unicode strings, make a GetTickCount before and after the loop and you'll see how damn fast your CPU is...   :-)

Regards, Madshi.
BRONZE EXPERT

Commented:
jup, madshi,correct.
that conversion should not take to much performance.

Author

Commented:
Ok, that is fine. Then I will be confidence and will remain my code

Explore More ContentExplore courses, solutions, and other research materials related to this topic.