2012-08-16 69 views
0

有人可以告诉我如何在c#中声明winapi? 我有此错误:c winapi声明#

Error 1 The name 'WinApi' does not exist in the current context bla bla bla... 

的是:如果你不使用它提供的方法和常量库

WinApi.OpenProcess(WinApi.PROCESS_ALL_ACCESS, 0, (uint)aProc[0]); 
+2

如果你是想增加对Win32 OpenProcess API函数的声明,你可以看看文章[这里](http://henrikfalk.wordpress.com/ 2009/07/21/C-openprocess /)。 – 2012-08-16 18:11:42

回答

7

,你需要使用Platform Invocation Services (P/Invoke)自己实现这些。

例如:

public static class WinApi { 
    public const int PROCESS_ALL_ACCESS = /* whatever the value is */; 

    [DllImport("kernel32.dll")] 
    public static extern IntPtr OpenProcess(int dwDesiredAccess, 
     bool bInheritHandle, int dwProcessId); 
}