11-01-2012 12:10 AM
Hi,
When using GetFirstFile() / GetNextFile(), if a file is encountered with Chinese chars in it's filename, each of these chars is replaced with a "?".
As a result, I cant open the file as I dont know its full name.
Does anyone know of a way around this? Some Windows SDK function maybe?
cheers,
Darrin.
11-02-2012 11:41 AM
Hi Diz@work,
Thanks for posting on the NI Discusson Forums.
I have a couple questions for you in order to troubleshoot this issue:
CVI does include support for multi-byte characters. Take a look at this introduction:
http://zone.ni.com/reference/en-XX/help/370051V-01/cvi/programmerref/programmingmultibytechars/
As far as the Windows SDK goes, I did find that the GetFirstFile() and GetNextFile() functions are based on the Windows functions, FindFirstFile() and FindNextFile(). According to MSDN, these functions are capable of handling Unicode characters as well as ASCII:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364418(v=vs.85).aspx
There may be a discrepancy between how these functions are being called and/or what they're returning to the CVI wrapper functions.
11-02-2012 06:54 PM
Hi Frank,
1. OS is english. (win7x86, CVI2012)
2/3. The filename is concatenated by MakePathName() then being used by GetFileInfo() and OpenFile() only.
noMoreFiles = GetFirstFile (searchPath, 1, 1, 1, 1, 1, 0, filename);//seek 1st folder/file while (!noMoreFiles) { MakePathname (path, filename, filePathName); GetFileInfo (filePathName, &fileSize); filehdle = OpenFile (filePathName, VAL_READ_ONLY, VAL_APPEND, VAL_ASCII); ...
CloseFile(filehdle);
noMoreFiles = GetNextFile(filename);
}
where the actual filename of the file is "PX_丽玲.txt"
When the debugger breaks on OpenFile() (ret=-1, file not found), the value of each of the 2 chinese chars in 'filename' and 'filePathName' is '?' (ASCII 63), and each appears to be taking only a single byte (i.e. the termimating NULL appears at index 9 of 'filename'). GetFileInfo() gives fileSize of 0.
Do I have to do anything to enable multibyte /unicode?
cheers,
Diz
11-06-2012 05:30 PM
Hi Diz,
You don't need to enable any LabWindows/CVI settings in order to use multibyte characters, but you do have to make sure your code handles these characters appropriately. Please compare the two code snippets from the first link in my previous post on for an example of how to do this.
With that being said, it sounds like the fileName string you're getting is not multibytes characters, but instead ASCII characters. I would recommend trying to call the FindFirstFile() and FindNextFile() in the Win32 API as a next step. Did you take a look at the second link I sent in my previous post? Please also take a look at the following KnowledgeBase article on calling into the Win32 API:
http://digital.ni.com/public.nsf/allkb/4D03093F2079ABDD86256969006E9ECC?OpenDocument
Please let us know how this goes.