BBC BASIC for Windows
« How to OPEN(IN) a file with unicode filename? »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:54pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: How to OPEN(IN) a file with unicode filename?  (Read 573 times)
hellomike
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 46
xx 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
User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx 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 » User IP Logged

I like making program generators and like reinventing the wheel
DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx 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!

smiley

D
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx 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
User IP Logged

hellomike
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 46
xx Re: How to OPEN(IN) a file with unicode filename?
« Reply #4 on: Oct 11th, 2016, 10:12am »

Thanks for your help guys.

As you might have noticed, Richard answered in this thread:
http://bbcbasic.conforums.com/index.cgi?board=language&action=display&num=1476136244
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls