Hello,
I have a problem with using the Win32 method GetParent.
As I read in msdn, if this method is called on a handle which doesn't
have a parent (top level and unowned window) then the result is null,
the same for when the method fails.
They wrote that for distiguishing between failure, and a window
with no parent ,i have to use the GetLastError.
The problem is that when I call GetParent(handle) and the handle
doesn't have a parent, the GetLastError returns the same error which
was before calling the method GetParent, meaning the method didn't
change it all, so i can't know if the method failed or succeeded.As far
as know, the method should set the last error to SUCCESS so it can be
distiguishd.
Does someone know how i can distinguish between these two
situations??
Thanks
Mattias Sj?gren - 04 Jan 2005 12:05 GMT
In .NET you should use Marshal.GetLastWin32Error() rather than
GetLastError().
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
ezitech@yahoo.com - 04 Jan 2005 12:57 GMT
I used Marshal.GetLastWin32Error() and not GetLastError().
The same problem also exist with C++ code .
For example:
SetLastError(2);
int errorBeforeCall = GetLastError(); // =2
HWND parent = GetParent(hWnd);//parent = NULL because hWnd has no
parent
int errorAfterCall = GetLastError(); //=2 (The same as before!!)
And again, my question is how can I know if the hWnd has no parent or
if
the call failed??