K
krupa.p
Hi All,
I have created an unmanaged C++ dll project with some exported
functions in it. I am trying to call these functions from my VS 2005 C#
project for a Windows CE device using PInvoke. This seems to be working
fine except that the values returned by the functions (in unmanaged
Dll) are not proper.
Is there a way I can debug these functions in the unmanaged code? I
tried to create and write to a text file in these functions, but the
file is not created on the device at all. Can anyone tell me of a way I
can capture values returned by the function in the unmanged code?
Here is the code I used in the unmanaged function to write to a file.
-------------------------------------------------------------------------------------------------------------------------------
BRIGHTNESSCONTROL_API DWORD GetPowerStatus(LPBYTE power_status, LPDWORD
batt_life_time, LPBYTE batt_life_percent)
{
DWORD dwLen;
SYSTEM_POWER_STATUS_EX2 sps;
//file handle
HANDLE hFile;
//something to contain the number of bytes read
DWORD dwNumWritten;
//a boolean test variable, to test for success of reads
BOOL bTest;
//a buffer... can actually be of any type
DWORD dwBuffer;
dwLen = GetSystemPowerStatusEx2(&sps, sizeof(sps), TRUE);
*power_status = sps.ACLineStatus;
*batt_life_time = sps.BackupBatteryLifeTime;
*batt_life_percent = sps.BatteryLifePercent;
const WCHAR fp = (WCHAR) "\Storage Card\volume.txt";
//filepath = (WCHAR) "\storage card\volume.txt";
LPCWSTR filepath = &fp;
//*filepath = fp;
//dwBuffer = *pdwVolume;
hFile = CreateFile(filepath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if(hFile != INVALID_HANDLE_VALUE)
{
//SetFilePointer(hFile, 0, 0, FILE_END);
bTest= WriteFile(hFile, batt_life_time, sizeof(batt_life_time),
&dwNumWritten,NULL);
bTest= CloseHandle(hFile);
}
return dwLen;
}
I have created an unmanaged C++ dll project with some exported
functions in it. I am trying to call these functions from my VS 2005 C#
project for a Windows CE device using PInvoke. This seems to be working
fine except that the values returned by the functions (in unmanaged
Dll) are not proper.
Is there a way I can debug these functions in the unmanaged code? I
tried to create and write to a text file in these functions, but the
file is not created on the device at all. Can anyone tell me of a way I
can capture values returned by the function in the unmanged code?
Here is the code I used in the unmanaged function to write to a file.
-------------------------------------------------------------------------------------------------------------------------------
BRIGHTNESSCONTROL_API DWORD GetPowerStatus(LPBYTE power_status, LPDWORD
batt_life_time, LPBYTE batt_life_percent)
{
DWORD dwLen;
SYSTEM_POWER_STATUS_EX2 sps;
//file handle
HANDLE hFile;
//something to contain the number of bytes read
DWORD dwNumWritten;
//a boolean test variable, to test for success of reads
BOOL bTest;
//a buffer... can actually be of any type
DWORD dwBuffer;
dwLen = GetSystemPowerStatusEx2(&sps, sizeof(sps), TRUE);
*power_status = sps.ACLineStatus;
*batt_life_time = sps.BackupBatteryLifeTime;
*batt_life_percent = sps.BatteryLifePercent;
const WCHAR fp = (WCHAR) "\Storage Card\volume.txt";
//filepath = (WCHAR) "\storage card\volume.txt";
LPCWSTR filepath = &fp;
//*filepath = fp;
//dwBuffer = *pdwVolume;
hFile = CreateFile(filepath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if(hFile != INVALID_HANDLE_VALUE)
{
//SetFilePointer(hFile, 0, 0, FILE_END);
bTest= WriteFile(hFile, batt_life_time, sizeof(batt_life_time),
&dwNumWritten,NULL);
bTest= CloseHandle(hFile);
}
return dwLen;
}