PDA

Click to See Complete Forum and Search --> : My program seems jammed during the call of long Api


Conogelato
Jun 4th, 2001, 09:56 PM
My program seems jammed during the call of long Api.
The program reads portions of files from the disk and writes them on Cdrom (with direct cd) through the Api WriteFile , and Createfile
Public Declare Function WriteFile Lib "kernel32"
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA"

The size of each file is of 100 [mb].
During the call of the Api, that lasts many minutes, the WHOLE program stops answering and stops repaint the screen. The program came back to respond at the end of the Api-writing operations.
I have tried with doevents, but he doesn't do nothing..
Does anybody know how do it transparent way, without give the impression that the system is jammed?

Nucleus
Jun 4th, 2001, 10:03 PM
Conogelato, can you direct me to site(s)/info about writing to a cd from VB?

jim mcnamara
Jun 4th, 2001, 10:08 PM
Write a separate little hunk of code to do the writing - then call the code and wait for it to end while allowing DoEvents like this

ExecCmd("c:\MyShortCodeHunk.exe -parameters")


Option Explicit
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long

Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&

Public Sub ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ReturnValue As Integer

' Initialize the STARTUPINFO structure:
start.cb = Len(start)

' Start the shelled application:
ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

' Wait for the shelled application to finish:
Do
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
DoEvents
Loop Until ReturnValue <> 258

ReturnValue = CloseHandle(proc.hProcess)
End Sub


You can use ShellExecute and WaitForSingleObject, also

Search the www.vbapi.com reference for "waitforsingleobject" for sample code for that.

Conogelato
Jun 4th, 2001, 10:10 PM
if yu use "direct cd" from hp, that program Not use any Iso or whatever cdrom filesystenm, but make a emulation or fat32 in yours cd.
That menning your cd look like a hard drive for ANY windows operation.
is good, you can drop in cdrom any file from explorer.
I try to find some iso ocx, i found one, but not work

Conogelato
Jun 4th, 2001, 10:48 PM
Tank a lot
but I am relatively new in Visual Basic, and your piece of code is too complex, I don't understand all.
The principal thing is that my program writes a file on the cd during a reading loop , and that the file comes written is the content of a byte array. (derived from the reading of a file of 2,5 gb on hard disk) ( did you remember the programs for chop large file in disckettes, my program do the seim in cds)
How i can pass the content of the array to an external program?