LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

GetFirstFile() and non-english chars

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.

 

 

0 Kudos
Message 1 of 4
(3,188 Views)

Hi Diz@work,

 

Thanks for posting on the NI Discusson Forums. 

 

I have a couple questions for you in order to troubleshoot this issue:

 

  1. Which language is your Windows operating system set to? Chinese or English?
  2. When you say that the filename returned contains '?' characters instead of the Chinese characters, do you mean you see this when you output to a message popup panel or print to the console? Are you looking at the values in fileName as you're debugging? Can you take a look at the actual numerical values in the fileName array and see which characters they map to? It's possible that the Chinese characters are being returned correctly, but the function you're using to output them doesn't understand the codes they use.
  3. Which function are you using to open the file with the fileName you get from GetFirstFile()? Can you take a look at what's being passed to it?

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.

0 Kudos
Message 2 of 4
(3,164 Views)

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

 

0 Kudos
Message 3 of 4
(3,157 Views)

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.

0 Kudos
Message 4 of 4
(3,118 Views)