c# - Usage of WriteFile function produces a 1(success), yet return an error code of 87 -
I am currently using WriteFile function to restrict the watchdog expires in embedded systems. The function actually works, but it also returns the error code 87. Tried to debug the parameter in the function, I still get the error code.
marshalling part: [DllImport ( "Coredllkdll", SetLastError = True)] private static extern int WriteFile (IntPtr hwnd, byte [] lpInBuffer, uint nNumberOfBytesToWrite, ref uint lpNumberOfBytesWritten, IntPtr lpOverlapped ); Uses: Byte [] Logic = New Byte [1]; Arg [0] = 0x87; UIT written byte = 0; Int returnWatchDogTouch = 0; ReturnWatchDogTouch = WriteFile (InitDevices.DeviceHandleWDT, Arg, 1, rewritten, IntPtr.Zero); Int error = Marshal.GetLastWin32Error (); // Getting error value 87 in this line The return value of the return is WatchDogTouch 1, and the error code of 87 is back in line after any help is appreciated, Thank you.
GetLastError is not set up necessary actions when they are successful, some functions In that case, set the value to zero, and nothing else. You should call only GetLastError to get more specific error information after a function indicates you failure to call. In your case, WriteFile gives 1 to success.
Comments
Post a Comment