0

What exactly does this exception mean, and why it is happening?

More info:

This is where it happens:

Id = GlobalAddAtom("aString");

if (Marshal.GetLastWin32Error() != 0)
{ throw new Win32Exception(); }

I know that GlobalAddAtom is indeed in kernel32.dll (that's where I'm DllImporting it from).

user2320724
  • 666
  • 3
  • 10
  • 18
  • [MSDN - The specified procedure could not be found.](http://msdn.microsoft.com/en-us/library/ms832056.aspx) – Maggy May Apr 30 '13 at 00:56
  • But what does that even mean? If I DllImport and call NonExistantFunction() from kernel32.dll then I get a totally different exception: "Unable to find an entry point named 'NonExistantFunction' in DLL 'kernel32.dll'.". Meaning that GlobalAddAtom() is indeed in kernel32.dll. So it is in the "module", correct? – user2320724 Apr 30 '13 at 16:04

1 Answers1

1

GetLastError returns the last error that any API function triggered.

Check that the returned Id value is zero - only in that case did GlobalAddAtom fail.

  • Thanks, doesn't really help me though.. I already know its a Win32Exception meaning it came from the Win32 function call. Just don't understand why it's happening.. especially since GlobalAddAtom() is returning a negative value (not zero) which means it is not failing. – user2320724 Apr 30 '13 at 15:58
  • 1
    OK, your answer was not entirely explicit, but you're right. The Win32Exception was there from before my call to GlobalAddAtom(). It seems that it was even there at very beginning of my program. What has to be done is check the return value of GlobalAddAtom(), and only if it fails then we can use GetLastWin32Error(). – user2320724 Apr 30 '13 at 16:18