For GDI DCs, the usual way that MS does is :
IntPtr hDC = GetWindowDC(this.Handle);
if (hDC != IntPtr.Zero)
{
// Code....
ReleaseDC(this.Handle, hDC);
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am calling the windows api directly from C#, and I found an issue calling GetWindowDC(); we were not releasing the device context (ReleaseWindowsDC()), and therefore we exceeded the max number, which caused it to return 0. Having said that, it occurs to me that there might be other reasons this and other api calls fail (i.e. timing).
If I get a null back, should I call Marshal.GetLastWin32Error(), and then retry the call on certain circumstances? Are there any other API calls that I should consider doing retries on? If so, where can I find documentation on this?
For GDI DCs, the usual way that MS does is :
IntPtr hDC = GetWindowDC(this.Handle);
if (hDC != IntPtr.Zero)
{
// Code....
ReleaseDC(this.Handle, hDC);
}
Yes. GetLastError() and then according to the error code, you can retry the call at right time on your circumstance.