Help in API

  • Thread starter Thread starter Arnaldo Fuziy
  • Start date Start date
A

Arnaldo Fuziy

We're trying to do a few things here without success and I would like to ask
for your help, please.
1) Disable and re-enable auto suspend
have found that we could P/Invoke
SystemParametersInfo(SPI_SETBATTERYIDLETIMEOUT, 0, NULL, TRUE) but haven't
found any working example and have no idea on how to start

2) Get free disk space
we could P/Invoke GetDiskFreeSpaceEx but no working example either

3) Get free memory
P/Invoke GlobalMemoryStatus, no working example either

4) Get remaining battery
- P/Invoke GetSystemPowerStatusEx - have found an example but couldn't get
it to work
- could use OpenNetCF.BatteryStatus but I still don't want to go that way...
I'd rather P/Invoke it myself...

Tks very much,

Arnaldo.
 
Here are a couple of the ones you wanted in C#. It looks like Alex has
provided links to similar examples and the others on your list.

public class MEMORYSTATUS
{
public uint dwLength;
public uint dwMemoryLoad;
public uint dwTotalPhys;
public uint dwAvailPhys;
public uint dwTotalPageFile;
public uint dwAvailPageFile;
public uint dwTotalVirtual;
public uint dwAvailVirtual;
}

[DllImport("CoreDll.dll", EntryPoint="GlobalMemoryStatus")]
public static extern void GlobalMemoryStatus
(
MEMORYSTATUS lpBuffer
);

[DllImport("CoreDll.dll", EntryPoint="GetSystemMemoryDivision")]
public static extern int GetSystemMemoryDivision
(
ref uint lpdwStorePages,
ref uint lpdwRamPages,
ref uint lpdwPageSize
);

Use...

uint storePages = 0;
uint ramPages = 0;
uint pageSize = 0;
int res = GetSystemMemoryDivision(ref storePages, ref ramPages, ref
pageSize);

MEMORYSTATUS memStatus = new MEMORYSTATUS();
GlobalMemoryStatus(memStatus);

--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks very much, Alex and Geoff... I'll try the sample codes you've sent...
 
With your fine help, we've got working:

- Disk space is fine...
- Battery info returns the battery info but not the backup battery... Is
there anything else I could do?
- The memory status returns 163208757280 and 80906463648210944 for length
and memory load; for 0 and 123004564856111104 totalphysical and
availphysical... Means nothing (at least) for me... The function
GetSystemMemoryDivision reports NotSupportedException...
- The most important for us: the idle timeout... It doesn't do anything,
meaning, I set it to "n" numbers and it doesn't change anything... What am I
missing?

Tks again,

Arnaldo.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top