Marshal.GetLastWin32Error errors

A

Alex

Hello,

I have a problem with Marshal.GetLastWin32Error()
Every call returns 127 (ERROR_PROC_NOT_FOUND) even if the previous call was successful.

For example, given:

namespace Utils
{
public class Win32
{
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
}
}

And this code:

int rc;
IntPtr hwnd = Win32.FindWindow("something", "something else");
rc = Marshal.GetLastWin32Error();

The call to FindWindow() succeeds (hwnd gets a non-null value)
but Marshal.GetLastWin32Error() returns 127.

What am I doing wrong?

Thanks,
Alex.
 
M

Mattias Sjögren

What am I doing wrong?

GetLastWin32Error is only relevant if the previously called function
failed. If it succeeds, there's no point in calling GetLastWin32Error.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top