newbieforever wrote:I extract this filename by fil = mid(stg, pos, lngth) because I am able to find out pos and lngth. No chance to convert fil to a form which can be used e.g. in CreateFileW()?
It would be helpful if you posted full code for that. For example, does your attempt to read with the mid() function fail also for #Define Unicode?
In the meantime, here is the code to write to a Unicode file:
Code: Select all
#Define winapimode 1 ' for playing with the two options
#Include "file.bi"
#include "Windows.bi"
Sub savefile(filename As wstring, p As String)
Print "Opening [";filename;"]"
if winapimode then
Dim As any ptr n, pstr
Dim As Integer byteswritten
n=CreateFileW(filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0)
If n<>-1 then
WriteFile(n, Peek(any ptr, VarPtr(p)), Len(p), @byteswritten, 0)
Print byteswritten; " bytes written"
CloseHandle(n)
Else
Print "Unable to open " + filename
End If
else
Dim As Integer n
n=freefile
If Open(filename For Binary Access Write As #n)=0 then
Put #n,,p
Close
Else
Print "Unable to open " + filename
End If
endif
End Sub
winapimode 0 (i.e. use the standard FB syntax) works fine if the filename is not "true" Unicode, e.g. "MyFile.txt"