In my C# application I'm trying to use the TDM_CLICK_BUTTON
message to click a button in a TaskDialog. This basically works just fine. What I expect to happen, happens. I even receive the TDN_BUTTON_CLICKED
notification.
But the documentation says, that the return value of SendMessage
would be nonzero if the call succeeds. But it always returns zero for me.
This is my code:
public void ClickButton( int buttonId ) {
bool success = UnsafeNativeMethods.SendMessage(
WindowHandle,
(uint)UnsafeNativeMethods.TASKDIALOG_MESSAGES.TDM_CLICK_BUTTON,
(IntPtr)buttonId,
IntPtr.Zero ) != IntPtr.Zero;
if( !success ) {
int lastWin32Error = Marshal.GetLastWin32Error();
throw new Win32Exception( lastWin32Error, "SendMessage for TDM_CLICK_BUTTON failed." );
}
}
lastWin32Error
is always zero when the exception is thrown. Which would be another indicator that everything is fine.
SendMessage
is declared in my code like this:
[DllImport( "user32.dll", SetLastError = true )]
internal static extern IntPtr SendMessage( IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam );
Is the documentation incorrect or am I using the message incorrectly?