Vista TaskDialog Wrapper:无法在DLL“ComCtl32”中找到名为“TaskDialogIndirect”的入口点

时间:2012-01-21 10:15:40

标签: c# excel-dna

我尝试使用Vista TaskDialog Wrapper and Emulator,我遇到以下异常:

“无法在DLL'ComCtl32'中找到名为'TaskDialogIndirect'的入口点。”

...在一个简单的控制台应用程序中:

class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

        PSTaskDialog.cTaskDialog.MessageBox(
            "MessageBox Title",
            "The main instruction text for the message box is shown here.",
            "The content text for the message box is shown here and the text willautomatically wrap as needed.",
            PSTaskDialog.eTaskDialogButtons.YesNo,
            PSTaskDialog.eSysIcons.Information
        );
     }
}

我做错了什么?

更新:

实际上,我正在使用excel-dna处理Excel插件。如何控制Excel加载的内容?

http://exceldna.codeplex.com/discussions/286990#post728888

2 个答案:

答案 0 :(得分:1)

我有一段时间没有参加过Office编程,但我的猜测是Excel加载了两个版本的comctl32,因此您可能需要使用Activation Context API将您的代码定向到包含TaskDialog的版本。解决问题的一些想法(不是解决方案):

  • 出于测试目的,对活动进程中的所有模块进行临时枚举 - 只是为了检查6.10是否实际加载(请参阅下面的这个枚举的简单示例,尽管意图不同)。 / p>

  • 使用Activation Context API获取正确的版本。 Example of use from C# (for enabling themes by way of comctl32 6.0) here

  • 或者(我从来没有让它在我工作的WPF应用程序中可靠地工作),创建一个对话框抽象类,它根据您可用的版本回退到MessageDlg。可能有更好的方法来进行检查,但是......:

FileVersionInfo version = ProcessUtils.GetLoadedModuleVersion("comctl32.dll");

if (version != null && version.FileMajorPart >= 6 && version.FileMinorPart >= 1)
{
   // We can use TaskDialog...
}
else
{
   // Use old style MessageBox
}

模块的枚举:

internal static FileVersionInfo GetLoadedModuleVersion(string name)
{
   Process process = Process.GetCurrentProcess();
   foreach (ProcessModule module in process.Modules)
   {
      if (module.ModuleName.ToLower() == name)
      {
         return module.FileVersionInfo;
      }
      return null;
   }
}

答案 1 :(得分:-1)

除了所有其他人所说的内容:如果您将ForceEmulationMode上的PSTaskDialog设置为true,则此错误将消失。