Reg: How to share variable information between two drivers in Windows CE 5.0 RRS feed

  • Question

  • Hi,

    One variable will be declared and modified in power button driver.

    I wan't to access that variable (only to read) in keyboard driver.

    Can any one tell how to do it in Windows CE 5.0


    Wednesday, April 3, 2013 11:14 AM

All replies

  • Using Device IOCONTROL



    Wednesday, April 3, 2013 12:12 PM
  • Hi GSR,

    Thanks for the reply.

    Will it not work with post message and get message ?

    I just want to read one bool variable in keyboard driver which will be set or unset by power button driver.


    Wednesday, April 3, 2013 12:26 PM
  • Do your drivers have message loops? It seems unlikely that they would. There are various methods for one-directional data transfer: registry values, DeviceIoControl codes, point-to-point message queues.

    Paul T.

    • Proposed as answer by Keshava GN Thursday, April 4, 2013 2:16 PM
    Wednesday, April 3, 2013 3:47 PM
  • To add to Paul's list, memory mapped files, shared memory location, events...

    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG

    Eurotech Inc.

    Thursday, April 4, 2013 1:53 PM
  • You can use a DWORD value in the registry also.  Simplest method.
    Thursday, April 4, 2013 8:19 PM
  • shared registry location is easy, but perhaps too slow.  Also, which ways make it easiest to synchronize (or serialize) access across processes or threads?

    does Windows CE support named pipes?  what about named mutexes?

    Thursday, April 4, 2013 10:11 PM
  • To share a variable information between drivers, here is a method ...

    declare the variable as global and export it using ... an example for you ...

    /********** Under your power button driver *********************/

    __declspec(dllexport) HANDLE hPowerSimulationUsingKey;

    /* accessing the variable here as ... just an example */

    hPowerSimulationUsingKey = CreateEvent(NULL,0,TRUE,NULL);

            /* Reset the event */

            /* Wait for key press */
            WaitForSingleObject(hPowerSimulationUsingKey, INFINITE);

            /* Close the power key simulation handle */


    The variable needs to be defined in .def file as


    Similarly, import the same variable in your keypad driver and set it there when ever there is a key press ....

    Hope this will help ...

    --- Misbah

    Senior Design Engineer T.E.S Electroni Solutions (Bangalore-India)

    • Proposed as answer by Keshava GN Friday, April 5, 2013 7:37 AM
    Friday, April 5, 2013 5:04 AM
  • Misbah:

    That is interesting, but I am missing something in your explanation.   How would another driver use that, and/or why does hPowerSimulationUsingKey need to be exported?

    You do say to import it in another driver, but you don't say how.  Are you thinking use LoadLibrary/GetProcAddress?   If so, why is that needed to use an event?  This looks like a complex way to avoid using a named event.

    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG

    Eurotech Inc.

    Friday, April 5, 2013 2:44 PM
  • Hi,

    Thanks to all for your repsonses.

    I am new to WinCE. Hence, I am little bit confused about judging the possible solution for my query.

    Hence, request you to suggest any solution to start with......

    Monday, April 8, 2013 9:38 AM
  • The trouble with that request is that you haven't told us much about your problem.   So giving you a solution would be premature.   All we really know is that you have information, a bit, in one driver that you want to access from another driver.  When, how often, why...?

    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG

    Eurotech Inc.

    Monday, April 8, 2013 12:46 PM
  • Similar to Misbah's method, you could use a named event (created in both drivers), this method is one of the safer and easier methods, but it is pretty limited in terms of sharing data.

    event = CreateEvent(NULL, FALSE, FALSE, "sharedEvent");

    If you create events with the same name in both the keypad driver and the other driver then use the keypad to set the event and monitor the event in your other driver using 

    DWORD waitResult = WaitForSingleObject(event, 500);
    if(waitResult == WAIT_OBJECT_0){

    //event has been detected





    If you want to share more data, you could use shared memory protected by something like a shared mutex, but you have to be VERY CAREFUL:

    mutex = CreateMutex(NULL, FALSE, "sharedMutex");

    sharedMem = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,0,(bufLength+3)*sizeof( unsigned char ),"sharedMemory");
    shared_FileMemory = (unsigned char*)MapViewOfFile(sharedMem, FILE_MAP_ALL_ACCESS, 0,0,0 );

    Note that the memory is also named ("sharedMemory")

    Before accessing the memory, you have to first obtain the mutex handle

    DWORD waitResult = WaitForSingleObject(mutex, 500);
    if(waitResult == WAIT_OBJECT_0){

    //you can now read/write the memory






    • Edited by tomleijen Wednesday, April 10, 2013 7:47 PM
    Tuesday, April 9, 2013 8:35 PM