簡體   English   中英

在應用程序啟動時出現EntryPointNotFoundException TaskDialog,但稍后運行良好

[英]EntryPointNotFoundException TaskDialog at start of Application but runs fine later

我直接從Windows API Pack for .NET(包裝器)獲得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);
}

謝謝你的時間 :)

喬希

從MSDN嘗試此解決方案-

步驟1:在解決方案資源管理器中右鍵單擊您的項目

步驟2:選擇->添加->新項目

步驟3:添加一個應用程序清單文件,該文件在VS 2010中為app.manifest

步驟4:取消注釋最后一個xml節,從依賴項標簽開始直到/ dependency

該代碼應如下所示-

<dependency>
<dependentAssembly>
 <assemblyIdentity
  type="win32"
  name="Microsoft.Windows.Common-Controls"
  version="6.0.0.0"
  processorArchitecture="*"
  publicKeyToken="6595b64144ccf1df"
  language="*"
 />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM