RAPI problems using CeGlobalMemoryStatus function from my desktop app

C

Coder

I'm having some trouble using the RAPI "CeGlobalMemoryStatus" function.
Below is the error information, MSDN documentation for the
"CeGlobalMemoryStatus" function and the code used in my class and app.

The "CeGlobalMemoryStatus" function takes a long pointer to a MEMORYSTATUS
structure.
My VB .NET desktop application uses the class and code below (Class) and
(App)

Can you see a problem or do you have a similar rapi example that uses a long
pointer to a structure?

Thanks very much for looking at this!

----------I get this error--------------
I get this error when I run the desktop application. Other RAPI functions
work correctly.

An unhandled exception of type
'System.Runtime.InteropServices.MarshalDirectiveException' occurred in My
MyApp.exe

Additional information: PInvoke restriction: can not return variants.
-----------------------------------------


---- MSDN Doucumentation ----
void CeGlobalMemoryStatus(
LPMEMORYSTATUS lpmst
);

typedef struct _MEMORYSTATUS {
DWORD dwLength;
DWORD dwMemoryLoad;
DWORD dwTotalPhys;
DWORD dwAvailPhys;
DWORD dwTotalPageFile;
DWORD dwAvailPageFile;
DWORD dwTotalVirtual;
DWORD dwAvailVirtual;
} MEMORYSTATUS, *LPMEMORYSTATUS;
---------------------------------


(Class)

<DllImport("rapi.dll", CharSet:=CharSet.Unicode)> _
Private Shared Function CeGlobalMemoryStatus(ByRef stMemory As
MEMORYSTATUS)
End Function

Public Structure MEMORYSTATUS
Public dwLength As Integer
Public dwMemoryLoad As Integer
Public dwTotalPhys As Integer
Public dwAvailPhys As Integer
Public dwTotalPageFile As Integer
Public dwAvailPageFile As Integer
Public dwTotalVirtual As Integer
Public dwAvailVirtual As Integer
End Structure

Private stCEMemory As New MEMORYSTATUS

Public Function GetMemoryInfo() As Integer
CeRapiInit()
CeGlobalMemoryStatus(stCEMemory) '<--- the error happens here
'...
CeRapiUninit()
End Function


(App)
iMemsize = oRAPI.GetMemoryInfo
 

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