【发布时间】:2012-03-30 20:09:02
【问题描述】:
我有一个使用 TaskDialog library 的 WinForms 应用程序,它利用 ComCtl32.dll 中的 Vista 样式对话框,对于较小的操作系统,它使用模拟的 win 表单...
但这不是问题...这个库工作正常,我们从来没有遇到过问题。到现在为止...事实上,如果我们在正常情况下启动一个对话框,那么它看起来很好。
但是,我在主窗体上添加了一个拖放处理程序,以捕获从其他来源(例如 Windows 资源管理器)删除的文件路径。如果该拖放处理程序是第一次显示对话框,那么我们会得到以下异常:
无法在 DLL“ComCtl32”中找到名为“TaskDialogIndirect”的入口点。
这发生在第三方库调用:
/// <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 );
如果已显示对话框,则处理程序将运行正常。
表单的 DragDrop 处理程序未显示 InvokeRequired,但我还是小心翼翼地通过 Form.Invoke 引发了对话框。
private void MainForm_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
Array fileNames = (Array)e.Data.GetData(DataFormats.FileDrop);
if (fileNames != null && fileNames.OfType<string>().Any())
{
foreach (var fileName in fileNames.OfType<string>())
{
this.Invoke(new Action<string>(this.AttemptOpenFromPath), fileName);
}
}
}
}
另一方面:我正在 64 位 Windows 7 机器上编译(并运行)它,但带有“AnyCPU”架构标志。
关于为什么只在第一次调用 TaskDialogIndirect 是通过 DragDrop 处理程序时引发异常的任何想法/解决方案???
【问题讨论】:
-
这取决于库的工作方式。
-
异常发生在什么操作系统上?
-
该错误告诉您,当您尝试调用
TaskDialogIndirect函数时,它不可用。该功能在 Windows Vista 之前不存在,因此在旧版本的 Windows 上,它将失败。它与拖放无关。 -
@SLaks - 它发生在我的 Windows 7 机器上。但是,我对它通常工作的事实感到困惑(建议存在依赖的 Comctl32 库)......但只有在第一次通过 DragDrop 处理程序引发对话框时才会失败。
-
DragDrop 处理程序中的线程有什么不寻常的地方吗?
标签: c# winforms winforms-interop comctl32 taskdialog