CreateToolhelp32Snapshot生成了ERROR_NOT_ENOUGH_MEMORY

时间:2013-12-07 18:32:52

标签: c# .net-3.5 windows-mobile windows-ce out-of-memory

在Windows Mobile 6专业版设备中,我尝试调用 CreateToolhelp32Snapshot 函数,但出现 ERROR_NOT_ENOUGH_MEMORY 错误。

我已经按照建议的here使用了标志 TH32CS_SNAPNOHEAPS 。 代码是C#.NET 3.5 Compact Edition。

我的目标是通过它的名字找到一个过程。

private const int TH32CS_SNAPPROCESS = 0x00000002;
private const int TH32CS_SNAPNOHEAPS = 0x40000000;
private const int INVALID_HANDLE_VALUE = -1;

[DllImport("toolhelp.dll", SetLastError = true)]
private static extern IntPtr CreateToolhelp32Snapshot(uint flags, uint processID);

public static IntPtr FindProcessPID(string fullpath)
{
    fullpath = fullpath.ToLower();
    IntPtr snapshot_handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | TH32CS_SNAPNOHEAPS, 0);

    if ((Int32)snapshot_handle == INVALID_HANDLE_VALUE)
        throw new Win32Exception(Marshal.GetLastWin32Error(), "CreateToolhelp32Snapshot failed.");

感谢。

1 个答案:

答案 0 :(得分:0)

我的代码中唯一的差异似乎是您对CreateToolhelp32Snapshot的调用中的硬代码进程ID:

        uint procID = 0;
        IntPtr pHandle = CreateToolhelp32Snapshot(SnapshotFlags.Process | SnapshotFlags.NoHeaps, procID);

我的CpuMon的网页:http://www.hjgode.de/wp/2012/12/14/mobile-development-a-remote-cpu-monitor-and-cpu-usage-analysis/

完整代码:http://code.google.com/p/win-mobile-code/source/browse/trunk/cpumon/ProcessorUsage/CpuMon2/Process.cs

相关问题