none
WEC7 Control Panel Power Properties not showing battery installed on date RRS feed

  • Question

  • I have ported a Windows CE 5.0 battery driver over to Windows Embedded Compact 7.0, along with the power properties applet in the control panel.

    When BatteryGetLifeTimeInfo() is called from the power properties applet, the pointer to the local variable to contain the system time structure gets corrupted, and the function returns 0 for all of the system time structure elements. I have followed the call through in a debug build, and the pointer goes wrong before entry to the function xxx_DeviceIoControl(). This results in the "installed on" line in the power properties dialogue showing garbage.

    All other calls from the power properties applet appear to work fine. All other aspects of the battery driver also appear to work ok - i.e. reading voltage, current, state of charge, charging, Good, Low etc. These all show the correct values in the power properties dialogue.

    Does anyone have any suggestion as to why this particular call is going wrong?

    Below is the section of code where the function call occurs in power.cpp:

    void BatteryOnChange(HWND hDlg, const PPOWER_BROADCAST ppb)
    {
        int         rgBatteryFlags[NUM_BATTERIES];
        int         iBattery;
        int         idcShow;
        
        #define LEN_TEMP    256
        TCHAR       szTemp1[LEN_TEMP];
        TCHAR       szTemp2[LEN_TEMP];

        PPOWER_BROADCAST_POWER_INFO ppbpi = (PPOWER_BROADCAST_POWER_INFO) ppb->SystemPowerState;

        // Optional stuff at bottom of prop-page

        // if supported by driver, get lifetime info
        szTemp1[0]=0;
        if(!BatteryDrvrSupportsChangeNotification())
        {
            // Hide these battery indicators if we don't support it (if not already hidden)
            if(IsWindowVisible(DI(rgOptionalCtls1[0])))
                ShowHide(hDlg, rgOptionalCtls1, ARRAYSIZEOF(rgOptionalCtls1), SW_HIDE);
        }
        else
        {
            SYSTEMTIME  stLastChange;
            DWORD       dwCpuUsage, dwPrevCpuUsage;
            int         iLen;
            DWORD        localeUserDefault, dateShortDate;
            
            // Show these battery indicators if we support them (if not already visible)
            if(!IsWindowVisible(DI(rgOptionalCtls1[0])))
                ShowHide(hDlg, rgOptionalCtls1, ARRAYSIZEOF(rgOptionalCtls1), SW_SHOW);
            
            BatteryGetLifeTimeInfo(&stLastChange, &dwCpuUsage, &dwPrevCpuUsage);
            DEBUGMSG(ZONE_POWER, (L"BatteryOnChange: BatteryGetLifeTimeInfo() returned lastChange date:\r\n"));
            DEBUGMSG(ZONE_POWER, (L"wYear:%d, wMonth:%d, wDayOfWeek:%d, wDay:%d\r\nwHour:%d, wMinute:%d, wSecond:%d, wMilliseconds:%d\r\n",
                stLastChange.wYear, stLastChange.wMonth, stLastChange.wDayOfWeek, stLastChange.wDay,
                stLastChange.wHour, stLastChange.wMinute, stLastChange.wSecond, stLastChange.wMilliseconds));
            RETAILMSG(1, (L"BatteryOnChange: BatteryGetLifeTimeInfo() returned lastChange date:\r\n"));
            RETAILMSG(1, (L"wYear:%d, wMonth:%d, wDayOfWeek:%d, wDay:%d\r\nwHour:%d, wMinute:%d, wSecond:%d, wMilliseconds:%d\r\n",
                stLastChange.wYear, stLastChange.wMonth, stLastChange.wDayOfWeek, stLastChange.wDay,
                stLastChange.wHour, stLastChange.wMinute, stLastChange.wSecond, stLastChange.wMilliseconds));
            
            // format LastChange as string
            if (!GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stLastChange, NULL, szTemp1, CCHSIZEOF(szTemp1)))
            {
                DWORD lastError = GetLastError();
                DEBUGMSG(ZONE_ERROR, (L"BatteryOnChange: ERROR GetDateFormat() returned 0. lastError = 0x%08x\r\n", lastError));
                RETAILMSG(1, (L"BatteryOnChange: ERROR GetDateFormat() returned 0. lastError = 0x%08x\r\n", lastError));
            }
            else
            {
                iLen = lstrlen(szTemp1);
                if(iLen+2 < CCHSIZEOF(szTemp1))
                {
                    szTemp1[iLen++] = L' ';
                    //lstrcpy(szTemp2, TEXT("HH':'MM"));
                    GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &stLastChange, NULL, szTemp1+iLen, CCHSIZEOF(szTemp1)-iLen);
                }
            }
            UpdateCtl(IDC_BAT1);
               

    Monday, September 16, 2013 3:06 PM