uses
"Console"
uses
"File"
uses
"UI"
dim
myTime
as
DWord
=
Timer
#Region "Declarations"
%INVALID_HANDLE_VALUE = &HFFFFFFFF
as
dword
%GENERIC_READ = 0x80000000
as
dword
%GENERIC_WRITE = 0x40000000
as
dword
%ERROR_FILE_NOT_FOUND = 2
%FILE_SHARE_DELETE = 0x00000004
as
dword
%FILE_SHARE_READ = 0x00000001
as
dword
%FILE_SHARE_WRITE = 0x00000002
as
dword
%OPEN_EXISTING = 3
as
dword
%FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000
as
dword
%FILE_ATTRIBUTE_SYSTEM = 4
as
dword
%FILE_FLAG_OVERLAPPED = 0x40000000
as
DWord
%FILE_FLAG_NO_BUFFERING = 0x20000000
as
DWord
Type
overlapped
Internal
as
quad
InternalHigh
as
quad
Offset
as
DWord
OffsetHigh
as
DWord
Pointer
as
Long
hEvent
as
long
end
type
TYPE
SECURITY_ATTRIBUTES
DWORD
nLength
AS
DWORD
lpSecurityDescriptor
AS
DWORD
bInheritHandle
AS
LONG
END
TYPE
Declare
Function
ReadFileEx
lib
"KERNEL32.DLL"
Alias
"ReadFileEx"
(
ByVal
hFile
As
Long
,
byref
lpBuffer
As
string
,
ByVal
nNumberOfBytesToRead
As
Long
,
byref
lpOverlapped
As
overlapped,
ByVal
lpCompletionRoutine
As
long
)
As
Long
DECLARE
FUNCTION
CreateFileA
lib
"KERNEL32.DLL"
ALIAS
"CreateFileA"
(
byref
lpFileName
AS
ASCIIZ
,
byval
dwDesiredAccess
AS
DWORD
,
byval
dwShareMode
AS
DWORD
,
byref
lpSecurityAttributes
AS
SECURITY_ATTRIBUTES,
byval
dwCreationDisposition
AS
DWORD
,
byval
dwFlagsAndAttributes
AS
DWORD
,
byval
hTemplateFile
AS
DWORD
)
AS
DWORD
Declare
Function
CloseHandle
lib
"KERNEL32.DLL"
Alias
"CloseHandle"
(
byval
hObject
as
DWORD
)
AS
LONG
declare
function
SleepEx
lib
"KERNEL32.DLL"
Alias
"SleepEx"
(
byval
dwMilliseconds
as
dword
,
byval
bAlertable
as
long
)
as
Long
#EndRegion
function
LpoverlappedCompletionRoutine(
byval
dwErrorCode
as
DWord
,
Byval
dwNumberOfBytesTransfered
as
DWORD
,
byval
lpOverlapped
as
long
)
as
Long
printl
"inside LpoverlappedCompletionRoutine"
printl
"errCode = "
& dwErrorCode
printl
"Bytes read = "
& dwNumberOfBytesTransfered
CONTROL
SET
TEXT
hDlg, %label2, lpBuffer
return
0
end
Function
Begin
ControlID
%Label1
%Label2
%Button1
End
ControlID
CALLBACK
Function
DlgCallback()
As
Long
Select
Case
CBMSG
Case
%
WM_Command
If
CBCTLMSG
= %
BN_CLICKED
Then
SELECT
CASE
cbctl
case
%Button1
call
start_read
end
Select
endif
Case
%
WM_DESTROY
MSGBOX
0,
"Window is to be destroyed."
End
Select
End
Function
function
start_read()
Global
voverlapped
as
overlapped
Global
hFile
as
Long
Global
lpBuffer
as
string
* 512
Local
lpSecurityAttributes
as
SECURITY_ATTRIBUTES
Local
result
as
long
Local
success
as
long
hFile = CreateFileA(sFileSource, %GENERIC_READ, %FILE_SHARE_READ, lpSecurityAttributes, %OPEN_EXISTING, %FILE_FLAG_NO_BUFFERING
or
%FILE_FLAG_OVERLAPPED,
Null
)
if
hFile <> %INVALID_HANDLE_VALUE
then
Printl
"File handle = "
& hFile
result = ReadFileEx(hFile, lpBuffer, 512, voverlapped, CodePtr(LpoverlappedCompletionRoutine))
readInProgress = %
TRUE
printl
"ReadFileEx result (<> 0 means no error) : "
& result
Else
Printl
"Failed to get a file handle."
in
%CONSOLE_FOREGROUND_RED
or
%CONSOLE_FOREGROUND_INTENSITY
success = %
FALSE
endif
if
success = %
FALSE
then
Return
%
FALSE
Else
Return
%
TRUE
endif
end
Function
Function
TBMain
()
as
Long
Local
count
as
Integer
Global
hDlg
as
DWord
Global
sFileSource
as
asciiz
Global
fileSize
as
DWord
Global
readInProgress
as
Boolean
sFileSource =
"t:\pg200.txt"
fileSize = FILE_Size(sFileSource)
Printl
"File : "
& sFileSource
Printl
"Size (Bytes) : "
& fileSize
call
MakeUi
Do
DIALOG
DOEVENTS
0
To
Count
SleepEx(1,%
TRUE
)
updateLabel1
Loop
While
Count
closeHandle(hFile)
end
function
Function
updateLabel1()
Local
sLabel1
as
String
Local
nTime
as
DWord
nTime =
Timer
- myTime
sLabel1 =
"Script is running since : "
& nTime &
" seconds"
CONTROL
SET
TEXT
hDlg, %label1, sLabel1
end
function
Function
MakeUi()
DIALOG
NEW
0,
"form1"
, -1, -1, 195, 180, %
WS_DLGFRAME
OR
%DS_CENTER
OR
%
WS_CAPTION
OR
%
WS_SYSMENU
, 0
TO
hDlg
CONTROL
ADD
Label
, hDlg, %label1,
"..."
, 5, 15, 185, 15, %
WS_BORDER
OR
%ES_RIGHT, %WS_EX_CLIENTEDGE
CONTROL
ADD
Label
, hDlg, %label2,
"..."
, 5, 35, 185, 15, %
WS_BORDER
OR
%ES_RIGHT, %WS_EX_CLIENTEDGE
CONTROL
ADD
BUTTON
, hDlg, %button1,
"Start READ"
, 65, 80, 45, 20
DIALOG
SHOW
MODELESS
hDlg
Call
DlgCallback
end
function
Bookmarks