A problem with GetProcessMemoryInfo?

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
brown
Newbie
Newbie
Posts: 4
Joined: Sun May 18, 2008 8:39 am

A problem with GetProcessMemoryInfo?

Post by brown »

I have made a simple program, but results from both windows and wine are quite different. Is this a bug in my program or in wine? Any advice is appreciated :)

/*
result under windows:
{
}
[successed: 1085440]{
}

result under wine(linux):
{
}
[successed: 0]{
*/

#include <windows.h>
#include "psapi.h"
#include <stdio.h>
#include <stdlib.h>

#pragma comment ( lib, "psapi.lib" )

void GetCurrentProcessMemory ()
{
PROCESS_MEMORY_COUNTERS pmc;

printf("{\n}");

bool ret=GetProcessMemoryInfo ( GetCurrentProcess() , &pmc, sizeof ( pmc ) );

if (ret)
printf("\n[successed: %d]", (int)pmc.WorkingSetSize);
else
printf("\n<failed>");

printf("{\n}");

}

void main()
{
GetCurrentProcessMemory();
}
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: A problem with GetProcessMemoryInfo?

Post by vitamin »

brown wrote:I have made a simple program, but results from both windows and wine are quite different. Is this a bug in my program or in wine? Any advice is appreciated :)
bool ret=GetProcessMemoryInfo ( GetCurrentProcess() , &pmc,
It's not implemented in Wine:
http://source.winehq.org/source/dlls/ps ... ain.c#L520 calls http://source.winehq.org/source/dlls/nt ... ess.c#L211

You should use other functions available form kernel32 instead.
brown
Newbie
Newbie
Posts: 4
Joined: Sun May 18, 2008 8:39 am

Re: A problem with GetProcessMemoryInfo?

Post by brown »

vitamin wrote:
brown wrote:I have made a simple program, but results from both windows and wine are quite different. Is this a bug in my program or in wine? Any advice is appreciated :)
bool ret=GetProcessMemoryInfo ( GetCurrentProcess() , &pmc,
It's not implemented in Wine:
http://source.winehq.org/source/dlls/ps ... ain.c#L520 calls http://source.winehq.org/source/dlls/nt ... ess.c#L211

You should use other functions available form kernel32 instead.
Thanks for your reply.
I tried to use NtQuerySystemInformation instead, but it seems the function doesn't work well either. :(

NTSTATUS ns = NtQuerySystemInformation ( SystemProcessInformation, pspi, dSize, NULL );

http://source.winehq.org/source/dlls/ntdll/nt.c#L669
http://source.winehq.org/source/dlls/ntdll/nt.c#L762

BTW, wine's taskmgr.exe won't show real 'Mem Usage' under linux (but will under windows).
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: A problem with GetProcessMemoryInfo?

Post by vitamin »

brown wrote:NTSTATUS ns = NtQuerySystemInformation ( SystemProcessInformation, pspi, dSize, NULL );
You didn't read what I said - that function you trying to use is not implemented (that class in not implemented - just a stub). And I even linked it so you can see. And I told you to use other API available from kernel32.
austin987
Wine Developer
Wine Developer
Posts: 2383
Joined: Fri Feb 22, 2008 8:19 pm

A problem with GetProcessMemoryInfo?

Post by austin987 »

On Sun, May 18, 2008 at 4:42 PM, vitamin <[email protected]> wrote:
brown wrote:
NTSTATUS ns = NtQuerySystemInformation ( SystemProcessInformation, pspi, dSize, NULL );
You didn't read what I said - that function you trying to use is not implemented (that class in not implemented - just a stub). And I even linked it so you can see. And I told you to use other API available from kernel32.





I filed a bug for you:
http://bugs.winehq.org/show_bug.cgi?id=13302
brown
Newbie
Newbie
Posts: 4
Joined: Sun May 18, 2008 8:39 am

Post by brown »

vitamin wrote:
brown wrote:NTSTATUS ns = NtQuerySystemInformation ( SystemProcessInformation, pspi, dSize, NULL );
You didn't read what I said - that function you trying to use is not implemented (that class in not implemented - just a stub). And I even linked it so you can see. And I told you to use other API available from kernel32.


I really read it, but I don't have a clue how to do it with kernel32 APIs. :?
austin987 wrote:I filed a bug for you:
http://bugs.winehq.org/show_bug.cgi?id=13302
Thanks, although I'm not sure if it can be defined as a bug. :)
austin987
Wine Developer
Wine Developer
Posts: 2383
Joined: Fri Feb 22, 2008 8:19 pm

Post by austin987 »

Doesn't compile:

austin@austin-desktop:~$ i586-mingw32msvc-gcc foo.c
foo.c: In function ‘GetCurrentProcessMemory’:
foo.c:14: error: ‘bool’ undeclared (first use in this function)
foo.c:14: error: (Each undeclared identifier is reported only once
foo.c:14: error: for each function it appears in.)
foo.c:14: error: expected ‘;’ before ‘ret’
foo.c:17: error: ‘ret’ undeclared (first use in this function)
foo.c: In function ‘main’:
foo.c:27: warning: return type of ‘main’ is not ‘int’
John Drescher

A problem with GetProcessMemoryInfo?

Post by John Drescher »

On Sun, Nov 16, 2008 at 7:24 PM, austin987 <[email protected]> wrote:
Doesn't compile:

austin@austin-desktop:~$ i586-mingw32msvc-gcc foo.c
foo.c: In function 'GetCurrentProcessMemory':
foo.c:14: error: 'bool' undeclared (first use in this function)
foo.c:14: error: (Each undeclared identifier is reported only once
foo.c:14: error: for each function it appears in.)
foo.c:14: error: expected ';' before 'ret'
foo.c:17: error: 'ret' undeclared (first use in this function)
foo.c: In function 'main':
foo.c:27: warning: return type of 'main' is not 'int'
This does not appear to have anything at all to do with wine. Correct
me if I am wrong.

John
austin987
Wine Developer
Wine Developer
Posts: 2383
Joined: Fri Feb 22, 2008 8:19 pm

A problem with GetProcessMemoryInfo?

Post by austin987 »

On Sun, Nov 16, 2008 at 6:36 PM, John Drescher <[email protected]> wrote:
On Sun, Nov 16, 2008 at 7:24 PM, austin987 <[email protected]> wrote:
Doesn't compile:

austin@austin-desktop:~$ i586-mingw32msvc-gcc foo.c
foo.c: In function 'GetCurrentProcessMemory':
foo.c:14: error: 'bool' undeclared (first use in this function)
foo.c:14: error: (Each undeclared identifier is reported only once
foo.c:14: error: for each function it appears in.)
foo.c:14: error: expected ';' before 'ret'
foo.c:17: error: 'ret' undeclared (first use in this function)
foo.c: In function 'main':
foo.c:27: warning: return type of 'main' is not 'int'
This does not appear to have anything at all to do with wine. Correct
me if I am wrong.

John

Someone posted a program they wrote that doesn't work in wine. I
created a bug for them, and when checking up on old bugs today
realized it didn't compile. I posted in the original thread that it
didn't compile, so the original author can update/fix it.

--
-Austin
brown
Newbie
Newbie
Posts: 4
Joined: Sun May 18, 2008 8:39 am

Post by brown »

I modified the code to:

Code: Select all

#include <windows.h>
#include "psapi.h"
#include <stdio.h>
#include <stdlib.h>

#pragma comment ( lib, "psapi.lib" )

void GetCurrentProcessMemory ()
{
   PROCESS_MEMORY_COUNTERS pmc;

       printf("{\n}");

       bool ret=GetProcessMemoryInfo ( GetCurrentProcess() , &pmc, sizeof ( pmc
) );

       if (ret)
               printf("\n[successed: %d]", (int)pmc.WorkingSetSize);
       else
               printf("\n<failed>");

       printf("{\n}");

}

int main()
{
       GetCurrentProcessMemory();
       return 0;
}
I can compile it on my debian with: i586-mingw32msvc-gcc foo.cpp -lpsapi
Locked