ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames
Go Back  Xtreme Visual Basic Talk > > > ReadFile through API; reason: Unicode filenames


Reply
 
Thread Tools Display Modes
  #1  
Old 12-18-2016, 03:32 PM
addysftw addysftw is offline
Newcomer
 
Join Date: Dec 2016
Posts: 3
Default ReadFile through API; reason: Unicode filenames


Hi, everybody,

I am using VB6 since quite a long time, however since one month ago i had to run it on a computer with Win10.

I was working at an app which compare files to find duplicates in various directories, recursively. This used to work fine, but i decided to make it to work also with Unicode because i have many files and folders which have filename which were inaccessible by my old code.

I got stucked in the way how VB send strings to API calls, and i am tried various ways, but in the last three days i got tired by trying various ways and sometimes is working, sometimes not...

First i created a list of files, in folders, recursively using FindFirstFileW, FindNextFileW

fHandle = FindFirstFileW(StrConv(sAnsiInitDir & "*.*", vbUnicode), WFD)
where WFD was a structure WIN32_FIND_DATA

these were working perfectly, maybe i didn't tested yet all possibilities.. anyway

I had used CreateFileW to obtain a handle to a file to be readed, passing as parameter the StrPtr of the Unicode filename. This gave me a positive handle, in a range of several thousands (not some big number like i saw at other function calls)

I had found the API call of the ReadFile function, but it's passing the byte array to be filled BYVALUE, which is making the whole process slower.

ret& = ReadFile(lFileHandle, byval sWhatToGet, nBytesToRead, nBytesReaded, o)

I have been stuck once severeal hours because i miscall sWhatToGet byref....

I would like if a function exists to which to be passed the array or string to be filled, by Ref, because i think it'll be faster to not fill a long string (byte array) with zeroes or spaces, after that to pass that string to the stack, to be taken by the function, filled with info from file, passed back... by value is far slower than byref, i'm thinking...
The function needs to read from file in chunks, not all file at once. Because may be huge files to be processed...
Many thanks for help..
Reply With Quote
  #2  
Old 12-18-2016, 06:39 PM
addysftw addysftw is offline
Newcomer
 
Join Date: Dec 2016
Posts: 3
Default

Problem. Looks like the Strconv function from VB6 is not making a proper conversion to Unicode; when FindFirstFile receive a converted string from a real Unicode folder name, it returns invalid handle...
Reply With Quote
  #3  
Old 12-19-2016, 02:34 AM
Flyguy's Avatar
FlyguyReadFile through API; reason: Unicode filenames Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 19,164
Default

Have a look at this post on vbForums by Bonnie West:
Rename , Open, read Unicode files-VBForums
Reply With Quote
  #4  
Old 12-19-2016, 12:43 PM
addysftw addysftw is offline
Newcomer
 
Join Date: Dec 2016
Posts: 3
Default

Many, many thanks!!

Yes, it works!
But not from the beginning. I have tried first to use only the instruction
hFindFile = FindFirstFileW(StrPtr(ParentFolder & "\*"), VarPtr(WFD))
but VB6 refuses, did not want VarPtr; said "Type mismatch"
When applied without Varptr, the API function fails;


after some work, I decided to copy also the type and api declarations in the module header, ....and it works. I had them in another module and i considered they are same (at first sight)
There are small differences in the declarations. I do not know exactly why my previous didn't worked...
For the moment i'm happy with it as is now, tomorrow i'll look carefully to see why didn't worked in my version.

THANK YOU!
Reply With Quote
Reply

Tags
function, files, file, unicode, string, filled, array, api, folders, filename, calls, readfile, byref, passed, swhattoget, slower, handle, passing, byte, wfd, recursively, nbytestoread, byval, nbytesreaded, stuck


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames
 
ReadFile through API; reason: Unicode filenames
ReadFile through API; reason: Unicode filenames
 
-->