C#封装kernel32.dll API

7

有没有任何包装kernel32 API的辅助类,包括所有的函数方法和结构体?或者有任何包装器生成器吗?

我想要像这样的C#中kernel32.dll的所有方法:

 [DllImport("kernel32.dll",EntryPoint="RtlMoveMemory")]
        public static extern void RtlMoveMemory(int des, int src, int count);

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

        [DllImport("kernel32", CharSet = CharSet.Ansi)]
        public extern static int GetProcAddress(int hwnd, string procedureName);

        [DllImport("kernel32.dll", EntryPoint = "GetModuleHandle")]
        public static extern int GetModuleHandle(string lpModuleName);

        [DllImport("kernel32.dll", EntryPoint = "VirtualAllocEx")]
        public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);

        [DllImport("kernel32")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool CloseHandle(IntPtr hObject);

        [DllImport("kernel32", EntryPoint = "CreateRemoteThread")]
        public static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, uint lpThreadId);

        [DllImport("kernel32.dll", EntryPoint = "WriteProcessMemory")]
        public static extern IntPtr WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, uint size, IntPtr lpNumberOfBytesWritten);

3
入口点太多了,总共有1359个。一定要使用好的声明来源,你现有的那些是错误的。 - Hans Passant
如果生成所有入口点,之后就不会浪费时间去做它。而且生成源代码更好,代码中没有错误。 - alhambra eidos kiquenet
1个回答

7

哦,是的,但不支持VS 2008!!太遗憾了!!还有其他工具或源代码类可以拥有kernel32.dll的所有功能吗?谢谢。 - alhambra eidos kiquenet
1
VS插件可能不支持2008,但这并不意味着你不能使用网站上的内容。虽然搜索API并复制代码似乎很繁琐,但仍比从头开始编写要好。好处是你只需要做一次就可以了。 - donovan
繁琐地搜索API并复制代码...也许对我来说有点麻烦,但是有没有什么实践解决方案,可以自动化生成kernel32.dll、gdi.dll等包装器的代码?谢谢! - alhambra eidos kiquenet

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接