I am trying to start a process and get GetProcessIoCounters to work without success. I am always getting "Invalid access to memory location". Could anybody give advice.
Here is my code:
if (!CreateProcessA("c:\\app.exe",NULL,NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
printError(TEXT("CreateProcess Err"));
PIO_COUNTERS ioc = 0 ;
if(!GetProcessIoCounters(hProcess, ioc))
printError(TEXT("GetProcessIoCounters Err"));
else
{
wprintf(L"%lu %lu \n", hProcess, ioc->ReadOperationCount);
答案 0 :(得分:3)
While is not clear from where you get the process handle hProcess
, and supposing that it is correct, in GetProcessIoCounters
you must provide a pointer to an existing IO_COUNTERS
structure, not just a pointer to it.
Try:
if (!CreateProcessA("c:\\app.exe",NULL,NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
printError(TEXT("CreateProcess Err"));
IO_COUNTERS ioc = {0} ;
if(!GetProcessIoCounters(hProcess, &ioc))
printError(TEXT("GetProcessIoCounters Err"));
else
{
wprintf(L"%lu %lu \n", hProcess, ioc.ReadOperationCount);