Wrapper C# for kernel32.dll API
Asked Answered
M

1

8

Any helper class anywhere which wrapps kernel32 APIs, with all functions-methods and structures? Or any wrapper generator?

I want ALL methods of kernel32.dll in C# like this:

 [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);
Millstream answered 21/12, 2009 at 21:47 Comment(2)
There are 1359 entrypoints, way too much. Be sure to use a good source for declarations, the ones you've got are wrong.Pellicle
If generate all entrypoints, after not waste time to do it. And generate source code is better, not errors in codeMillstream
S
8

I doubt it.

Have you seen http://www.pinvoke.net/?

Strongbox answered 21/12, 2009 at 21:49 Comment(4)
Oh, yeah, but not support VS 2008 !!! it's a pity !! another tool or source code class with all functions of kernel32.dll ?? thanksMillstream
The VS plugin may not support 2008, that doesn't mean you can't use the content from the website. It may seem laborious searching for the APIs and copying out the code, but it's still better that writing it from scratch. On the plus side you only need to do this once.Contemplation
laborious searching for the APIs and copying out the code .... perhaps, but any practice solution for me, to automation code generation for wrapper of kernel32.dll, gdi.dll, ... THANKS !!Millstream
The link is brokenLovettalovich

© 2022 - 2024 — McMap. All rights reserved.