User`s guide
Opening and Closing Connection with a Device
5-11
HANDLE CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes,
SIZE_T dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId
);
For an adaptor, the following table lists the parameters you must set. For complete
information about creating a thread, see the documentation at the Microsoft Developer
Network Web site (msdn.microsoft.com).
Parameter Description
lpStartAddress Address of the acquisition thread procedure. Specify the name of
the thread procedure declared in your adaptor class header file.
See “Implementing the Acquisition Thread Function” on page
5-18.
lpParameter Pointer to the object itself, i.e., the this pointer.
lpThreadId Address of a variable in which the CreateThread() function
returns the ID assigned to the newly created thread
After you call the CreateThread() function, applications typically call the
PostThreadMessage() function to send a message to the new thread. This causes
the system to create a message queue for the thread. Enter a loop to wait until the
thread acknowledges the message was received to ensure that the thread queue has been
created. Your adaptor terminates the thread in your adaptor's closeDevice() function
— see “Suggested Algorithm for closeDevice()” on page 5-13.
Example: Opening a Connection
This example shows a skeletal implementation of an openDevice() function.
1
Replace the stub implementation of the openDevice() function in the MyDevice
adaptor with this code.
bool MyDeviceAdaptor::openDevice()
{
// If device is already open, return true.
if (isOpen())