Hi,
I have created a dll which permit to get two informations, the flag saying
if the PDA is in charge and the flag which is giving the batterylifepercent
information. I can get the batterylifepercent, but I can't get the second
information when I call the secound function "GetBattFlag". Here is the code :
-------------------------------------------------
// GetPowerBatt.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "Winbase.h"
#include "tchar.h"
#pragma comment(lib, "coredll.lib")
TCHAR a_szSUC[] = _T("1");
TCHAR a_szERR[] = _T("0");
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
int GetInfosBatt()
{
SYSTEM_POWER_STATUS_EX powerStatusEx;
int nBattValue = 0;
BOOL fRet = GetSystemPowerStatusEx(&powerStatusEx, true);
if(fRet)
{
nBattValue = powerStatusEx.BatteryLifePercent;
return nBattValue;
}
return -1;
}
int GetFlagBatt()
{
SYSTEM_POWER_STATUS_EX powerStatusEx;
int nFlagBatt = 0;
BOOL fRet = GetSystemPowerStatusEx(&powerStatusEx, true);
if(fRet)
{
nFlagBatt = powerStatusEx.BatteryFlag;
return nFlagBatt;
}
return -1;
}
///////////////////////////////////////////////////////
// Function: Retourne le pourcentage de batterie restante.
//
// Parameters:
// 1 [OUT] - Value
// 2 [OUT] - Result
extern "C" void GetBattInfos(TCHAR** pData)
{
static TCHAR pszData[33];
int flagVal = GetInfosBatt();
LPTSTR str1 = _T("");
char *buffer1 = "";
if(flagVal != -1)
pData[1] = a_szSUC;
else
pData[1] = a_szERR;
_itoa(flagVal, buffer1, 10);
int size1 = MultiByteToWideChar(CP_ACP, 0, buffer1, -1, NULL, 0);
MultiByteToWideChar(CP_ACP, 0, buffer1, -1, str1, size1);
pData[0] = str1;
}
///////////////////////////////////////////////////////
// Function: Retourne le flag de batterie disant si cell-ci est sur le puits
ou pas.
//
// Parameters:
// 1 [OUT] - Value
// 2 [OUT] - Result
extern "C" void GetBattFlag(TCHAR** pData)
{
int flagBatt = GetFlagBatt();
LPTSTR str2 = _T("");
char *buffer2 = "";
if(flagBatt != -1)
pData[1] = a_szSUC;
else
pData[1] = a_szERR;
_itoa(flagBatt, buffer2, 10);
int size2 = MultiByteToWideChar(CP_ACP, 0, buffer2, -1, NULL, 0);
MultiByteToWideChar(CP_ACP, 0, buffer2, -1, str2, size2);
pData[0] = str2;
}
-------------------------------------------------------
Thanks for any help.