// ================================================ ========================================================== ======================================
// Author:
// Norains
// Date:
// Saturday 25-feb-2006
// ================================================ ========================================================== ======================================
The control panel has many components that communicate directly with the driver. The process is generally as follows (in the example of creating a "mybacklightchange" event ):
1. initialize the driver, create a thread, and create a communication event within the thread
Class mydriver
{
....
PRIVATE:
Void myinit ();
// A thread processing program. Note that it must be declared as static here. Otherwise, an error occurs during compilation (pb4.1). I don't know why.
Static DWORD winapi mybacklightchangethreadproc (pvoid parg );
....
}
// Driver initialization function:
Mydriver: myinit ()
{
....
//-------------------------------
// Create a thread
Handle hmythread;
DWORD dwmythreadid;
// After the createthread function is called, it enters the mybacklightchangethreadproc thread processing function.
Hmythread = createthread (null, 0, mybacklightchangethreadproc, 0, 0, & dwmythreadid );
// Because mybacklightchangethreadproc is an endless loop, it is generally not executed until the thread is closed.
If (hmythread! = NULL)
{
Closehandle (hmythread );
}
....
}
2. Call the waitforsingleobject () function to wait for the dead loop body inside the driver thread.
DWORD winapi soclcd: mybacklightchangethreadproc (pvoid parg)
{
// Create a backlight event. The event name must be the same as the event name created on the control panel.
Handle hevent = createevent (null, false, false, l "mybacklightchange ");
// Endless loop, constant acceptance of information
While (true)
{
// If the control panel does not send a signal, the thread will remain at the waitforsingleobject
Waitforsingleobject (hevent, infinite );
//-------------------------------------------------------------------------
// It will be executed here only after the signal is obtained
// Perform related operations here, such as reading and writing the registry and operation register.
//-------------------------------------------------------------------------
}
Closehandle (hevent );
Return 0;
}
3. Next, let's see how the control panel sends signals.
DWORD sendevent ()
{
// Create an event here. Note: The event name must be the same as the name received by the driver; otherwise, the driver cannot obtain the signal.
Handle hevent = createevent (null, false, false, l "mybacklightchange ");
If (hevent! = NULL)
{
// Send the signal
Setevent (hevent );
Closehandle (hevent );
Return true;
}
Return false;
}
The control panel in Windows CE communicates with the hardware component by using this mechanism with the driver. The only difference is that the component writes the registry and then sends a signal. After the driver receives the signal, read the Registry first and operate the hardware based on the read value.