|
-
May 2nd, 2001, 11:44 AM
#1
Thread Starter
Lively Member
CreateThread API
How can i use CreateThread API to create another thread for a mcisendstring saving of a .wav file ? The purpose is to multitask in the sense that while VB compiler is executing the rest of my code & concurrently ,the 'extra' thread is saving my recorded voice on the microphone into a file ?
-
May 2nd, 2001, 01:26 PM
#2
Frenzied Member
CreateThread Example
Code:
'In a form
'Add a command button to the form
Private Sub Command1_Click()
'After you click this button, try to move the window
'You will see that the AsyncThread-function was executed asynchronously
hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf AsyncThread, ByVal 0&, ByVal 0&, hThreadID)
CloseHandle hThread
End Sub
Private Sub Form_Unload(Cancel As Integer)
'If the thread is still running, close it
If hThread <> 0 Then TerminateThread hThread, 0
End Sub
'In a module
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public hThread As Long, hThreadID As Long
Public Sub AsyncThread()
'Let this thread sleep for 10 seconds
Sleep 10000
hThread = 0
End Sub
-
May 2nd, 2001, 01:29 PM
#3
Frenzied Member
If you need to know what the parameters are
Code:
· lpThreadAttributes
Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpThreadAttributes is NULL, the handle cannot be inherited.
Windows NT: The lpSecurityDescriptor member of the structure specifies a security descriptor for the new thread. If lpThreadAttributes is NULL, the thread gets a default security descriptor.
Windows 95: The lpSecurityDescriptor member of the structure is ignored.
· dwStackSize
Specifies the size, in bytes, of the stack for the new thread. If 0 is specified, the stack size defaults to the same size as that of the primary thread of the process. The stack is allocated automatically in the memory space of the process and it is freed when the thread terminates. Note that the stack size grows, if necessary.
CreateThread tries to commit the number of bytes specified by dwStackSize, and fails if the size exceeds available memory.
· lpStartAddress
The starting address of the new thread. This is typically the address of a function declared with the WINAPI calling convention that accepts a single 32-bit pointer as an argument and returns a 32-bit exit code. Its prototype is:
DWORD WINAPI ThreadFunc( LPVOID );
· lpParameter
Specifies a single 32-bit parameter value passed to the thread.
· dwCreationFlags
Specifies additional flags that control the creation of the thread. If the CREATE_SUSPENDED flag is specified, the thread is created in a suspended state, and will not run until the ResumeThread function is called. If this value is zero, the thread runs immediately after creation. At this time, no other values are supported.
· lpThreadId
Points to a 32-bit variable that receives the thread identifier.
-
May 2nd, 2001, 02:43 PM
#4
PowerPoster
You can write all the code neeeded for saving the file in a function of class module or a standard module. Then use the CreateThread to start a new thread and call the function for saving the recording in that thread. This way, your recording will be saved inthe background.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|