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?
So I took the C++ Windows SDK TaskDialog sample and tried this message out in there as well. The return value of
SendMessageremains zero always.I noticed that a
TDN_BUTTON_CLICKEDnotification will always be sent (even if the button id does not exist). If the button exists or not has no effect on theSendMessagereturn value.Then I suspected, that the return value for that notification might have an effect, but no matter what I return from the callback (
TRUE/FALSE/S_OK/42), mySendMessagereturn value remains zero.So, given that I found no way to make this fail and/or return a nonzero value, I can only assume that the documentation is incorrect.
edit: I got a reply to my documentation feedback I sent a few days ago. Turns out the documentation is indeed incorrect. The return value is to be ignored.