Home > Back-end >  Why do I always 0 VirtualQueryEx back? To you big help.
Why do I always 0 VirtualQueryEx back? To you big help.

Time:09-22

Why do I always 0 VirtualQueryEx back? Seek help from your bosses,
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 cout <"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" & lt; cout cout <"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" & lt; cout<(VirtualQueryEx (h [0], (LPVOID) systemInfo. LpMinimumApplicationAddress, & amp; A, sizeof (a))==sizeof (a)) & lt; cout return 0;
}

CodePudding user response:

You use what error code GetLastError check

CodePudding 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 invalid

CodePudding user response:

Has been solved, the VirtualQuery is a process handle handle, I create threads, so the handle is invalid, thank you
  • Related