应用程序启动时的 EntryPointNotFoundException TaskDialog 但稍后运行良好
Posted
技术标签:
【中文标题】应用程序启动时的 EntryPointNotFoundException TaskDialog 但稍后运行良好【英文标题】:EntryPointNotFoundException TaskDialog at start of Application but runs fine later 【发布时间】:2012-09-28 03:42:39 【问题描述】:我有直接来自 .NET 的 WindowsAPI 包(包装器)的 TaskDialog 源,但是每当我尝试直接在我的程序的静态 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);
感谢您的宝贵时间:)
乔什
【问题讨论】:
【参考方案1】:从 MSDN 尝试这个解决方案 -
第 1 步:在解决方案资源管理器中右键单击您的项目
第 2 步:选择 -> 添加 -> 新项目
第 3 步:在 VS 2010 中添加应用程序清单文件,即 app.manifest
第 4 步:取消注释从依赖标记开始到 /dependency 的最后一个 xml 部分
代码应该看起来像这样 -
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
【讨论】:
这会中断对 Windows XP 及更早版本的支持吗? 嗯...我真的不确定。试一试以上是关于应用程序启动时的 EntryPointNotFoundException TaskDialog 但稍后运行良好的主要内容,如果未能解决你的问题,请参考以下文章