kernel32

C# GetProcAddress Returns Zero

萝らか妹 提交于 2019-12-29 05:19:24
问题 For some reason, whenever my C# .NET 2.0 application makes a call to GetProcAddress it always returns zero. public class MyClass { internal static class UnsafeNativeMethods { [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] internal static extern IntPtr LoadLibrary(string lpFileName); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] internal static extern bool SetDllDirectory(string lpPathName); [DllImport("kernel32.dll", CharSet = CharSet.Auto,

C# GetProcAddress Returns Zero

為{幸葍}努か 提交于 2019-12-29 05:19:05
问题 For some reason, whenever my C# .NET 2.0 application makes a call to GetProcAddress it always returns zero. public class MyClass { internal static class UnsafeNativeMethods { [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] internal static extern IntPtr LoadLibrary(string lpFileName); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] internal static extern bool SetDllDirectory(string lpPathName); [DllImport("kernel32.dll", CharSet = CharSet.Auto,

How to call DeviceIoControl to retrieve the amount of memory it needs?

陌路散爱 提交于 2019-12-25 14:00:31
问题 I'm trying to call DeviceIoControl(IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS) API, as shown here, but I need it to first "tell me" how much memory it needs (unlike the code I linked to.) So I call it as such: //First determine how much data do we need? BYTE dummyBuff[1]; DWORD bytesReturned = 0; if(!::DeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, dummyBuff, sizeof(dummyBuff), &bytesReturned, NULL)) { //Check last error int nError = ::GetLastError(); if(nOSError == ERROR

How do you call Win32 API functions from inline assembler?

我只是一个虾纸丫 提交于 2019-12-24 00:45:00
问题 Would somebody please tell me whats wrong with this code I am just calling a Sleep function from the kernel32.dll What's wrong? I am using Visual Studio 2008. Any help would be grateful. Thank you very much. __asm { mov eax, 77e2ef66h push 9999 call eax } 回答1: Where did you get that magic number, 77e2ef66h ? Usually if you're calling Win32 API functions from inline assembler, you'd do something like: __asm { push 9999 call Sleep } Functions in Win32 do not have a fixed address (regardless of

EnumResourceNames issue - unknown error

喜夏-厌秋 提交于 2019-12-22 13:57:35
问题 I was recently working with resources from secondary libraries/binary modules and encountered a strange error. I have two native WinAPI references: [DllImport("kernel32.dll", SetLastError = true)] public extern static bool EnumResourceNames(IntPtr hModule, int lpszType, EnumResNameProc lpEnumFunc, IntPtr lParam); [DllImport("kernel32.dll", SetLastError=true)] public extern static IntPtr LoadLibraryEx(string lpFileName, IntPtr hFile, int dwFlags); When I call LoadLibraryEx, I am getting the

ReadProcessMemory fails on some Pages (GetLastError()=299)

泄露秘密 提交于 2019-12-18 17:31:54
问题 I try to read all commited pages of a process (Win7-64). On most pages it works but it fails for a few pages. I cannot explain why. Here is my test programme (compiled x32, tested in Win7-64): #include <windows.h> void main() { HANDLE hProc = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION,FALSE,GetCurrentProcessId()); SYSTEM_INFO si; ZeroMemory(&si,sizeof(SYSTEM_INFO)); GetSystemInfo(&si); char* buf = new char[si.dwPageSize]; for (unsigned i = 0; i < 0x7fff0; i++) { void* baseOffs =

Do I need to pin an anonymous delegate?

泪湿孤枕 提交于 2019-12-18 07:48:11
问题 I am calling CopyFileEx from a C# application with an anonymous delegate being passed into the LPPROGRESS_ROUTINE parameter in order to get notifications on the file copy progress. My question is, does the anonymous delegate need to be pinned and why (or why not). In addition, does the answer change if: CopyFileEx was not blocking. If I passed in a delegate that was not anonymous. Thanks! 回答1: The delegate does not need to be pinned . A managed object is pinned if it cannot be moved by the

kernel32.dll is missing in Windows Phone 8.1 app thru NHunspell

删除回忆录丶 提交于 2019-12-13 21:05:22
问题 I'm trying to use NHunspell library in my windows phone app (available thru NuGet package). In the Hunspell constructor i'm getting this error: Additional information: Unable to load DLL 'kernel32.dll': The specified module could not be found. Does anyone know how why it happens and how can i fix it? i'm running my app in the emulator, maybe this cause the issue? The same code works fine in a simple desktop app, so i guess it is something with the project refrences or stuff like that... And

Can't find GetProcAddress in kernel32.dll export directory?

早过忘川 提交于 2019-12-13 07:40:05
问题 I'm trying to get the RVA of specific functions in kernel32.dll so I can use the RVA as an offset from the base address of kernel32.dll in a specified process to get the VA of the functions I need to inject my dll. I already wasn't able to find LoadLibrary but I did find LoadLibraryExA and used that instead for my dll injector however I now can't find GetProcAddress which I was going to use to locate the VA of functions in my ThreadProc function. So if I can't find it that means I'm going to

Any difference between kernel32.dll Sleep and Thread.Sleep()

陌路散爱 提交于 2019-12-12 11:01:27
问题 Is there any difference(performance, implementation. .whatever) between the following: i) DllImport("kernel32.dll")] public extern static void Sleep(uint msec); ..then call Sleep function ii) Thread.Sleep() 回答1: There's a big difference, actually. This blog post explains why managed threads should never do unmanaged blocking, if possible. The official MSDN documentation has the same guideline without all the underlying details. P.S. Thread.Sleep is a sign of a poorly-designed program. 回答2: I