rodrigocfd / winsafe

Windows API and GUI in safe, idiomatic Rust.
https://crates.io/crates/winsafe
MIT License
520 stars 30 forks source link

hImageList::ReplaceIcon Incorrectly Calls GetLastError() #138

Closed Carterpersall closed 2 months ago

Carterpersall commented 2 months ago

While troubleshooting an issue in my code, I was encountering errors from hImageList::ReplaceIcon. However, the error code being returned was 0 (Operation Completed Successfully). So I did some digging and found that ImageList_ReplaceIcon does not call SetLastError(), causing the returned error being the error code set by some previous command.

I confirmed this by calling SetLastError() myself with some other error code before calling hImageList::ReplaceIcon, and the error it returned was in fact the code I had set in SetLastError(). To further confirm that ImageList_ReplaceIcon does not call SetLastError(), I debugged my code in Visual Studio and viewed the disassembly of ImageList_ReplaceIcon, and confirmed that there are no code paths that lead to SetLastError().

See the problematic call to GetLastError() here

rodrigocfd commented 2 months ago

You're right. Unfortunately, there's no explanation on errors, and that's valid for all ImageList functions. I made them return E_FAIL on error, since there's nothing useful to be reported.

Let me know if this works for you.