Wince control panel and driver communication

Source: Internet
Author: User

// ================================================ ========================================================== ======================================
// 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.