Home > Software engineering >  "CreateFileW" is to open the file named as Unicode characters, but how to turn a Unicode f
"CreateFileW" is to open the file named as Unicode characters, but how to turn a Unicode f

Time:10-21

Use Windows GetOpenFileNameW is can solve the problem, but the premise is manually one by one file to choose

FileHwnd=CreateFile (VarPtr (UnicodeFileName (0)), GENERIC_READ, FILE_SHARE_READ, SA, OPEN_EXISTING, 0, 0)

Reoccupy after get handle ReadFile suck as the game in the heaven nes ROM file data, and then you can go with the contra,

There are more than 3000 games, but now I am in the directory I want to be a CRC check, not every game to choose once and then click, VB built-in function collapse, DIR, OPEN, these are not support Unicode,

Seen BBS have article reference object "Fso" short file name to solve, this can be used, but I want to rewrite the code, because in my code, scan files, open the file, the CRC check, three functions are all written in the book of a Function, and some of the game are compromised, I also wrote an algorithm to manually draw contra inside part data for signature verification, so I need to change the Function to engineering is very big,

Method now I can only think of that part of the code, can be to change the scanning file to replace the original DIR scanning with FindFirstFileW, but I can't find a any sample about this API, foreigners are very cow force, they reflect FindFirstFileA no, and post the clue to FindFirstFileW can, then that person to change, very cow force, but I don't cow force ah, I just want to make my friends happy to live, how to change to? I'm not a programmer, don't give me too profound cues, give me a little hint. I'll have to social security bureau on social security,

CodePudding user response:

See you say so a lot of an answer.
Actually vb is very suitable for w series function
 
Declare the Function CreateFile Lib "kernel32" Alias "CreateFileW" (ByVal lpFileName As long, ByVal dwDesiredAccess As long, ByVal dwShareMode As long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As long, ByVal dwFlagsAndAttributes As long, ByVal hTemplateFile As long) As long

Dim s as string
FileHwnd=CreateFile (STRPTR (s), GENERIC_READ, FILE_SHARE_READ, SA, OPEN_EXISTING, 0, 0)
So the inside is the unicode without conversion, remember the original statement byval xx as string instead as long line

CodePudding user response:

Appreciate it when I say so after a lot of people will see, but is to see a title

D plate has a file "?????????????????? .txt "

Dim s as string

S=dir (" d: \ ")

What do you think of this time s what is the value of a variable? The answer is "??????????????????????????????????
.txt "

So I'll use STRPTR ("??????????????????????????????????
". TXT) concluded that variable pointer, passed in

FileHwnd=CreateFile (STRPTR (s), GENERIC_READ, FILE_SHARE_READ, SA, OPEN_EXISTING, 0, 0)

Although I'm not in condition test, but I think FileHwnd will be equal to "1"

Just like that, when I didn't say anything

CodePudding user response:

Please try patience once, read my post, and then think about "how to turn a Unicode filename incoming parameters/variables",

Rather than "how pass in a variable into a Unicode", more is not "pass in a variable need not to need to Unicode",

CodePudding user response:

With W series first API access to the file of the unicode filename, then to createfileW

CodePudding user response:

Done, CopyMemory

But there is a small detail, in addition to such assignment still have what good method?

Dim buff (512) as byte

The game directory="C: "

Buff (0)=& amp; H43 & amp;
Buff (1)=& amp; H0 & amp;
Buff (2)=& amp; H3A & amp;
Buff (3)=& amp; H0 & amp;
Buff (4)=& amp; H5C & amp;
Buff (5)=& amp; H0 & amp;

I think, is the effect, according to the different directory, fu into an array of the corresponding hexadecimal values, (to corresponding unicode, each character of two Byte)

CodePudding user response:

This problem, the building Lord does not list and read UNICODE file.

The first to find a support UNICODE DIR, this word will API to write their own, or use VB.NET

API just I have an ANSI version, change can enumerate UNICODE filename:

 Option Explicit 
'the enumeration specifies the directory file.
'
'By widely spread-and deeply felt the old
'
http://www.m5home.com/
Private Const INVALID_HANDLE_VALUE As Long=1 & amp;
Private Const MAX_PATH As Long=260 & amp;

Private Type FILETIME
DwLowDateTime As Long
DwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
DwFileAttributes As Long
FtCreationTime As FILETIME
FtLastAccessTime As FILETIME
FtLastWriteTime As FILETIME
NFileSizeHigh As Long
NFileSizeLow As Long
DwReserved0 As Long
DwReserved1 As Long
CFileName (MAX_PATH - 1) As Byte
CShortFileName (14-1) As Byte
End Type
The Public Type byteFileName
BFileName () As Byte
End Type

Private Declare Function FindClose Lib "kernel32. DLL (_
ByVal hFindFile As Long As Long)
Private Declare Function FindFirstFile Lib "kernel32. DLL" Alias "FindFirstFileW" (_
ByVal lpFileName As Long, _
ByRef lpFindFileData As Long As WIN32_FIND_DATA)
Private Declare Function FindNextFile Lib "kernel32. DLL" Alias "FindNextFileW" (_
ByVal hFindFile As Long, _
ByRef lpFindFileData As Long As WIN32_FIND_DATA)
Private WFD As WIN32_FIND_DATA

Dim m_isSearch As a Boolean, isStop As Boolean
Dim m_outFiles () As byteFileName, m_outCount As Long

The Public Function ListFileW (ByVal sourceDir As String, ByRef outFiles () As byteFileName, Optional ByVal isCheckSub As Boolean=True) As Long
'list all files under the specified directory
'
ReDim m_outFiles (1000)
M_outCount=0
M_isSearch=True
IsStop=False

Call Dir_Api (sourceDir isCheckSub)
If m_outCount & gt; 0 Then
ReDim Preserve m_outFiles (m_outCount - 1)
OutFiles ()=m_outFiles ()
End the If
ListFileW=m_outCount
End the Function

The Public Function isSearch () As a Boolean
'whether the query is search
'
IsSearch=m_isSearch
End the Function

Public Sub StopSearch ()

'interrupt search process'
IsStop=True
DoEvents
End Sub

Private Sub Dir_Api (ByVal strPath As String, Optional ByVal isCheckSub As Boolean=True)
'
recursive process'
Dim dirCount As Long, Dirs () As String, hItem As Long
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • API
  • Related