嘿,我正在为我的智能手机做一个小应用程序,使用 Windows Mobile 6。我试图让所有当前正在运行的 processec,但方法 CreateToolhelp32Snapshot 总是返回 -1。所以现在我卡住了。我尝试调用 GetLastError() 方法时出错,但该方法返回 0 值。这是我的代码片段。
private const int TH32CS_SNAPPROCESS = 0x00000002;
[DllImport("toolhelp.dll")]
public static extern IntPtr CreateToolhelp32Snapshot(uint flags,
uint processid);
public static Process[] GetProcesses()
{
ArrayList procList = new ArrayList();
IntPtr handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if ((int)handle > 0)
{
try
{
PROCESSENTRY32 peCurr;
PROCESSENTRY32 pe32 = new PROCESSENTRY32();
// get byte array to pass to API call
byte[] peBytes = pe32.ToByteArray();
// get the first process
int retval = Process32First(handle, peBytes);