Here is my code (VirtualQueryEx function in the last ten lines) :
# include & lt; Iostream>
# include & lt; Windows. H>
# include & lt; Iomanip>
# include
using namespace std;
DWORD WINAPI alloction (LPVOID lpParam);
DWORD WINAPI track (LPVOID lpParam);
HANDLE h [2];
HANDLE x [2];
Int main ()
{
H [0]=CreateThread (NULL, 0, alloction, NULL, 0, NULL);
H [1]=CreateThread (NULL, 0, track, NULL, 0, NULL);
X [0]=CreateSemaphore (NULL, 1, 1, L "A");
X [1]=CreateSemaphore (NULL, 0, 1, L "B");
WaitForMultipleObjects (2 h, true, INFINITE).
The CloseHandle (h [0]);
The CloseHandle (h [1]);
system("pause");
return 0;
}
DWORD WINAPI alloction (LPVOID lpParam)
{
WaitForSingleObject (x [0], INFINITE);
VirtualAlloc (NULL, 1024, MEM_RESERVE, PAGE_READWRITE);
ReleaseSemaphore (x [1], 1, 0).
return 0;
}
DWORD WINAPI track (LPVOID lpParam)
{
The WaitForSingleObject (x [1], the INFINITE);
The MEMORYSTATUS lpBuffer;
SYSTEM_INFO systemInfo;
A MEMORY_BASIC_INFORMATION a;
ZeroMemory (& amp; A, sizeof (a));
GetSystemInfo (& amp; SystemInfo);
GlobalMemoryStatus (& amp; LpBuffer);
;
cout
}
CodePudding user response:
You use what error code GetLastError checkCodePudding user response:
I just tried, it returns a value is 6, said mean handle is invalid, but I this h0 is the global variables, why will handle invalidCodePudding user response:
Has been solved, the VirtualQuery is a process handle handle, I create threads, so the handle is invalid, thank you