Error Using LookupPrivilegeValue(...)

  • Thread starter Thread starter Liang Yitao
  • Start date Start date
L

Liang Yitao

I used DllImport() to load the function
LookupPrivilegeValue() in advapi32.dll, and then called
it in my button click event. But the function always
returns false. I got the error code it left through
GetLastError() function and the result is "997" which
means, in the system error code in MSDN, "Overlapped I/O
operation is in progress." I don't know what's wrong with
it. The calling code is as below:
 
Liang,

Are you using the SetLastError property of the DllImport attribute, and
the System::Runtime::InteropServices::Marshall::GetLastWin32Error
method? Do not use GetLastError with P/Invoke.

Also: I assume you meant to write LookupPrivilegeValue instead of
OpenProcessToken?

Bart Jacobs
 
Liang,
I used DllImport() to load the function
LookupPrivilegeValue() in advapi32.dll, and then called
it in my button click event. But the function always
returns false. I got the error code it left through
GetLastError() function and the result is "997" which
means, in the system error code in MSDN, "Overlapped I/O
operation is in progress." I don't know what's wrong with
it. The calling code is as below:


If you're using DllImport instead of using IJW, then make sure you set the
SetLastError property of the DllImport attribute to true. You'd probably be
better off then calling Marshal.GetLastWin32Error() instead of
GetLastError().
 
Oh, yes. I made a mistake ^_^
Thank you for your reply, and I'll try to do it in your
way.
 
Back
Top