TaskDialogソースはWindowsAPIPackfor .NET(ラッパー)から直接取得していますが、プログラムの静的なvoid Main()領域でTaskDialogを直接開こうとすると、EntryPointNotFoundExceptionがスローされます。ただし、TaskDialogが生成され、コードの後半で完全に正常に表示されます。なんでこれ?
EntryPointNotFoundExceptionをスローするコードは
/// <summary>
/// TaskDialogIndirect taken from commctl.h
/// </summary>
/// <param name="pTaskConfig">All the parameters about the Task Dialog to Show.</param>
/// <param name="pnButton">The push button pressed.</param>
/// <param name="pnRadioButton">The radio button that was selected.</param>
/// <param name="pfVerificationFlagChecked">The state of the verification checkbox on dismiss of the Task Dialog.</param>
[DllImport("ComCtl32", CharSet = CharSet.Unicode, PreserveSig = false)]
internal static extern void TaskDialogIndirect(
[In] ref TASKDIALOGCONFIG pTaskConfig,
[Out] out int pnButton,
[Out] out int pnRadioButton,
[Out] out bool pfVerificationFlagChecked);
しかし、私を驚かせるのは、異なる場所にある同一のコードが一度は機能するが、別の時間には機能しないという事実です。それは、参照などをロードしないプログラムと関係があるかもしれませんが、それは私の心を吹き飛ばします。私のアプリのエントリポイントのコードは
try
{
var taskDialog = new TaskDialog();
taskDialog.WindowTitle = ".NET Update Notification";
taskDialog.MainInstruction = "";
taskDialog.MainIcon = TaskDialogIcon.Error;
taskDialog.EnableHyperlinks = true;
taskDialog.Content =
"Your .NET Framework Version is out-of-date.\nPlease see <a href=\"***********\">the forums</a> for more info.\n\nSorry, but I can't continue without it.\n\n If you had the correct install this message wouldn't appear.";
taskDialog.Callback =
new TaskDialogCallback((ActiveTaskDialog _taskDialog, TaskDialogNotificationArgs _args, object _callbackData) =>
{
if (_args.Notification == TaskDialogNotification.HyperlinkClicked)
{
Process.Start(_args.Hyperlink);
}
return false;
});
var doItButton = new TaskDialogButton();
doItButton.ButtonId = 101;
doItButton.ButtonText = "Quit";
taskDialog.Buttons = new TaskDialogButton[] { doItButton };
int result = taskDialog.Show(null);
Application.Exit();
}
/*
* Handles the error message regarding ComCtl32.dll not being found.
* In the event of the beautiful TaskDialog above (which uses ComCtl32.dll)
* cannot be opened, fall back to an ugly as **** MessageBox with a '?' Help
* button in the title bar -.-
*/
catch (EntryPointNotFoundException)
{
MessageBox.Show(
"Your .NET Framework Version is out-of-date.\nTo find out how to get .NET 4.0 simply visit the forums at *********.\n\nSorry, but I can't continue without it :(",
".NET Update Notification", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
御時間ありがとうございます :)
ジョシュ