Author |
Topic: How to OPEN(IN) a file with unicode filename? (Read 573 times) |
|
hellomike
New Member
member is offline


Gender: 
Posts: 46
|
 |
How to OPEN(IN) a file with unicode filename?
« Thread started on: Oct 8th, 2016, 7:31pm » |
|
Hi,
In belows code, OPENIN() returns 0 when trying to open a file with an unicode filename.
Code:...
VDU 23,22,800;800;8,16,8,8
PRINT filename$
H%=OPENIN(filename$) The string from filename$ prints out OK, i.e. as unicode.
What should I change to make it work?
The current workaround I can think of is first copying the file with a neutral name to @tmp$ using the API call "SHFileOperationW" and then opening that copy instead.
I hope avoiding that though.
Thanks
Mike
|
|
Logged
|
|
|
|
michael
Senior Member
member is offline


Posts: 335
|
 |
Re: How to OPEN(IN) a file with unicode filename?
« Reply #1 on: Oct 10th, 2016, 02:27am » |
|
You may need to email Richard or leave a message on his forum concerning this subject. Its a bit beyond my knowledge and seems moderators are absent atm.
http://bbcbasic.conforums.com/
|
« Last Edit: Oct 10th, 2016, 02:29am by michael » |
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
DDRM
Administrator
member is offline


Gender: 
Posts: 321
|
 |
Re: How to OPEN(IN) a file with unicode filename?
« Reply #2 on: Oct 10th, 2016, 07:58am » |
|
I agree this would be a good one to run past Richard,as it's something he might want to add to his list of "things to change if I do another version"! Also, he knows what he's talking about...
Looking at the windows documentation, I see that the OpenFile function can't handle unicode. I don't know if this is what BB4W uses "under the hood" in the OPENIN function. There is an alternative, called "CreateFile" which has a W version (presumably "CreateFileW") which does handle unicode. It returns a handle to the file. I don't have time to try playing with it now, but you may then be able to use this just as you would any other file handle returned by OPENIN. You may need to close the file yourself, probably using CloseHandle.
I'm sure you realise, but others may not, that these are Windows API calls, so you'll need to use SYS, and you'll need to look up the right parameters, etc.
If you make it work, please post a simple example for the benefit of the rest of us!

D
|
|
Logged
|
|
|
|
DDRM
Administrator
member is offline


Gender: 
Posts: 321
|
 |
Re: How to OPEN(IN) a file with unicode filename?
« Reply #3 on: Oct 10th, 2016, 12:58pm » |
|
I tried this, which seems to work: Code: FILE_ATTRIBUTE_NORMAL = &80
GENERIC_READ = &80000000
OPEN_EXISTING = 3
SYS "CreateFile","Text1.txt",GENERIC_READ,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0 TO f%
WHILE NOT EOF#f%
INPUT#f%,q$
PRINT q$
ENDWHILE
CLOSE #f%
REM Test whether it's closed properly
f%=OPENIN"Text1.txt"
WHILE NOT EOF#f%
INPUT#f%,q$
PRINT q$
ENDWHILE
CLOSE #f%
I'd expect you to need to use CreateFileW to handle a unicode name string, but simply changing the name of the function failed. I suspect it may be necessary to convert the filename to UFT16 using MultibyteToWideChar: there's an example of how to do that in the section called "Displaying GIF and JPEG images", but I don't have time to play with it now...
D
|
|
Logged
|
|
|
|
|