Use of GlobalMemoryStatus causes System.NotSupportedException

G

Guest

Hi all,

I'm using Windows CE.net 4.2 with .NET 1.1. I'm trying to use the
GlobalMemoryStatus() subroutine to determine the percentage of memory used
for the whole system instead of just my application. I've P/Invoked (at
least I think this is what P/Invoking is) using the following:

Public Declare Sub GlobalMemoryStatus Lib "coredll.dll" Alias
"GlobalMemoryStatus" (ByVal lpBuffer As MEMORYSTATUS)

I've also created a structure:
Public Structure MEMORYSTATUS
Public dwLength As Long
Public dwMemoryLoad As Long
Public dwTotalPhys As Long
Public dwAvailPhys As Long
Public dwTotalPageFile As Long
Public dwAvailPageFile As Long
Public dwTotalVirtual As Long
Public dwAvailVirtual As Long
End Structure

and finally have a variable declared in which to store the information:
Public Mem As MEMORYSTATUS


When I get to this line in my code:
GlobalMemoryStatus(Mem)
I receive a System.NotSupportedException error.

I'm hoping rebuilding the platform is not the solution becuase that would be
a last resort for us. I've found the coredll.lib on my desktop but when I
try to add that as a reference in Solution Explorer I'm told that it must be
a DLL to be referenced. So I found a DLL but when I tried to reference that
Visual Studio told me it wasn't a valid .NET reference. I've looked through
my
C:\Program Files\Microsoft Visual Studio .NET
2003\CompactFrameworkSDK\v1.0.5000\Windows CE folder and don't see
coredll.dll anywhere.

Help?!? I have no clue what else to try to enable me to use the
GlobalMemoryStatus subroutine
 
G

Guest

Long in managed code is 64-bit, which is incorrect for the API. They should
be 32-bit Integer or Int32 values.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
G

Guest

So I should change the declaration of dwLength (and the rest of them) from
Long to Int? That's why I'm getting a NotSupportedException?
 
G

Guest

Sorry... meant change Long to Int32.

But I did that and I'm still getting a NotSupportedException
 
P

Paul G. Tobey [eMVP]

I don't think that you should be passing a big structure like that ByVal. C
wouldn't do that. Try ByRef.

Paul T.
 
G

Guest

Correct, the API takes a reference to the struct, so it should be going in
by ref (or change teh struct delcaration to a class)


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com



"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
 

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

Top