Schmidt
6/11/2012 1:25:00 PM
Am 11.06.2012 06:20, schrieb Jason Keats:
> Is it possible, using only VB6 code, to perform tasks asynchronously -
> without the use of ActiveX EXEs or third-party/closed-source DLLs?
The class I had in mind, is "selfcontained" and not
dependent on my libs.
Though it comes within the cairo-Tutorial-Download
(in Folder#: 14 Thumbnailing per ImageList).
www.datenhaus.de/Downloads/RC4cairoTutorial.zip
But to run the Demo (and the contained cAsyncFileRead.cls)
in a "useful context", you would have to install the
RC4-BaseLibs beforehand.
Or just take a look at the code within the Demo-Form
in the #14-Example, copy the class over into your own app -
and write your own FileLoop, based on what you find there...
Or just ask questions, in case you cannot get it to work.
The class is relatively simple - it is using overlapped IO
which is offered by the plain CreateFile/ReadFile Win32-API.
Though note, that apparently on Win7 (not sure about Vista)
the Overlapped (async)-behaviour is in the meantime only
"faked" - tried yesterday, to change the class to different
schemes (also based on the WIn32-API), but to no success.
Win7 stubbornly does not do anything asyncronous on the
File-Subsystem.
- the original Class is based on ReadFile and FILE_FLAG_OVERLAPPED
- tried ReadFileEx in combination with IOCompletion-Callbacks
- also tried IOCompletionPorts
All to no avail on WIn7 - I mean, the APIs deliver exactly
what one expects (e.g. ReadFile returns ERROR_IO_PENDING
also on Win7 - and later on the GetOverlappedResult-API
works the same as on XP ... it's just that on Win7 already
the *triggering* of the stuff per ReadFile does all the
complete FileReading under the hood - instead of (as on XP) -
doing nothing for the moment (aside from "noting" the Request)
and return ERROR_IO_PENDING.
So although Win7 returns the same async-error-notifications -
so that the usage of the async APIs is not broken -
its behaviour is not the same as on XP because it completes
the JOB already in the "initialization-call" - and then
hands out just "faked notification-results".
SO I tried to enhance the class yesterday, but neither
thing (IOCallbacks or IOCOmpletionPorts) worked - I mean
they "worked" - but asynchronously only on XP.
So it seems that for real async FileOps on Win7, one will
have to use threads finally.
-----------------------------------------------------
BTW, what's useful for testing such stuff is something
to clear the current System-Filecache (without rebooting):
'to be run within an App, which was started with Admin-rights
Public Sub CleanupFileCacheOnDrive(DriveChar As String)
Dim hFile As Long
hFile = CreateFile("\\.\" & Left$(DriveChar, 1) & ":", _
FILE_READ_ACCESS Or SYNCHRONIZE, _
FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0)
If hFile <> INVALID_HANDLE_VALUE Then CloseHandle hFile
End Sub
Here the Const- and Declare-stuff for the above:
Private Const INVALID_HANDLE_VALUE& = -1, OPEN_EXISTING& = 3
Private Const FILE_READ_ACCESS& = 1, SYNCHRONIZE& = &H100000
Private Const FILE_SHARE_READ& = 1, FILE_SHARE_Write& = 2
Private Declare Function CreateFile& Lib "kernel32" Alias "CreateFileA"
(ByVal lpFileName$, ByVal dwDesiredAccess&, ByVal dwShareMode&, ByVal
lpSecurityAttributes&, ByVal dwCreationDisposition&, ByVal
dwFlagsAndAttributes&, ByVal hTemplateFile&)
Private Declare Function CloseHandle& Lib "kernel32" (ByVal hObject&)
Olaf