Reputation: 21200
For the simple Messagebox, checking the http://pinvoke.net/, I get the
[DllImport("user32.dll")]
static extern MessageBoxResult MessageBox(IntPtr hWnd, string text, string caption, int type);
However the compiler reports MessageBoxResult could not be found. If I change MessageBoxResult to int, then it compiles fine. Any hint about this problem?
Upvotes: 1
Views: 445
Reputation: 48985
The definition is also given on pinvoke.net:
/// <summary>
/// Represents possible values returned by the MessageBox function.
/// </summary>
public enum MessageBoxResult : uint
{
Ok = 1,
Cancel,
Abort,
Retry,
Ignore,
Yes,
No,
Close,
Help,
TryAgain,
Continue,
Timeout = 32000
}
But as other mentioned, always check on MSDN that the value given by pinvoke.net is valid.
Upvotes: 2
Reputation: 48267
If you look at the MSDN page for the function, you'll see it does return an int, that's the native return type. I suspect pinvoke.net is glossing over that with the MessageBoxResult
, although their page mentions in two places that the function returns an int (just under messageboxresult it says "uint 0-6" and later in the example they write the function as returning an int). I'd recommend just using an int and handling that (or converting to DialogResult if possible).
Upvotes: 0
Reputation: 21855
MessageBoxResult is defined here:
System.Windows.MessageBoxResult
Upvotes: 1