Jump to content
Excelsior Forums
Sign in to follow this  
FrankFFM

Problems calling GetProcessMemoryInfo

Recommended Posts

Hi, I have problems calling

BOOL WINAPI GetProcessMemoryInfo(__in  HANDLE Process,__out  PPROCESS_MEMORY_COUNTERS ppsmemCounters,__in  DWORD cb)

My code:

// loop over all processes

for (int i=0; i < aProcCount/4;i++) {

// HANDLE WINAPI OpenProcess(__in  DWORD dwDesiredAccess,__in  BOOL bInheritHandle,__in  DWORD dwProcessId);

cd = new xFunction("Kernel32","int OpenProcess(int,int,int)");

       

Argument[] pd = new Argument[] {new Argument(0x0410),new Argument(0),new Argument(aProcOut)};

       

int han = ((Integer)cd.invoke(pd)).intValue();

System.out.println(">>" + han);

       

       

        // BOOL WINAPI GetProcessMemoryInfo(__in  HANDLE Process,__out  PPROCESS_MEMORY_COUNTERS ppsmemCounters,__in  DWORD cb);

        ce = new xFunction("Psapi","int GetProcessMemoryInfo(int,ProcessMemoryCounter,int)");

        ProcessMemoryCounter ppp = new ProcessMemoryCounter();

                   

        Argument[] pe = new Argument[] {new Argument(han),new Argument(ppp),new Argument(40)};

   

        if (((Integer)ce.invoke(pe)).intValue() == 0) {

            // DWORD WINAPI GetLastError(void)

            cf = new xFunction("Kernel32","int GetLastError()");

            int aCode = ((Integer)cf.invoke()).intValue();

 

            System.out.println(">>>" + aCode + " Error");

        }

        else

            System.out.println(">>>" + aBool);

}

ProcessMemoryCounter is defined as:

public class ProcessMemoryCounter extends Structure {

int cb = 40; //DWORD

int PageFaultCount; //DWORD 

int PeakWorkingSetSize; // SIZE_T

int WorkingSetSize; // SIZE_T

int QuotaPeakPagedPoolUsage; // SIZE_T

int QuotaPagedPoolUsage; // SIZE_T

int QuotaPeakNonPagedPoolUsage; // SIZE_T

int QuotaNonPagedPoolUsage; // SIZE_T

int PagefileUsage; // SIZE_T

int PeakPagefileUsage; // SIZE_T

@Override

public String defineLayout() {

// TODO Auto-generated method stub

return "int cb,int PageFaultCount,int PeakWorkingSetSize,int WorkingSetSize,int QuotaPeakPagedPoolUsage,int QuotaPagedPoolUsage," +

      "int QuotaPeakNonPagedPoolUsage,int QuotaNonPagedPoolUsage,int PagefileUsage,int PeakPagefileUsage";

}

}

I always get Error 998  as last error - any ideas why?

Share this post


Link to post
Share on other sites

I'm now a little bit wiser - a colleague of mine asked:

Error 998 is:

998 Invalid access to memory location. ERROR_NOACCESS

It appears the application doesn't have the right to access the memory.  There may be a permissions issue here.

Can you run as administrator or such?  Is it kernel level memory you're accessing or user mode?

> I think it will be a problem with the structure / the size of the structure. Any ideas around now?:huh:?

Share this post


Link to post
Share on other sites

When I made some experiments with an int[10] instead the structure there was no errorcode (but till now onyl 0 in the array elements). Making the array or the size of the area to store data (third parameter of the DLL call) smaller chause error message on the VM level. So it was the structure bnut I have no idea what's wrong anf why I do not get results back right now. Any ideas now from outer space?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×