How can I get the total physical memory in C#?

前端 未结 5 881
执笔经年
执笔经年 2020-12-15 23:56

I am using the GlobalMemoryStatusEx function to retrieve information about memory, but this function doesn\'t work correctly. It returns 0 for all properties. I

5条回答
  •  清酒与你
    2020-12-16 00:46

    I find my mistake from: http://www.pinvoke.net/default.aspx/kernel32/GlobalMemoryStatusEx.html

    I Changed

    internal static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer);
    

    To

    static extern bool GlobalMemoryStatusEx([In, Out] MEMORYSTATUSEX lpBuffer);
    

    and changed

    GlobalMemoryStatusEx(ref statEX);
    

    To

    GlobalMemoryStatusEx(statEX);
    

    It work correctly. Tanks

提交回复
热议问题