English 中文(简体)
在使用C#中专案时的切入点
原标题:EntryPointNotFoundException when using TaskDialog in C#
  • 时间:2009-10-23 09:34:22
  •  标签:

I m使用以下代码称“任务”。

    [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);

然而,我有例外,“无法找到一个称为DL ComCtl32”的切入点。

我拿到。 我正在使用Windows 7 x64(RC)。

我做了什么错误?

最佳回答

除此以外,别无一例外。

UPDATE: This probem had to do with side by side assemblies: these functions are present only in comctl32.dll version 6, but, for compatibility reasons, Vista will load an earlier version unless you tell it otherwise. The approach most people (including me) have been taking is to use a manifest. This has proven to be tricky, and may not be the right solution anyway, especially if what you re writing is a library: you don t necessarily want to force the entire application to use common controls 6.

正确的解决办法是推动“ 。 启动环境将使用正确版本的编号32.dll,而只剩下其余部分申请,不需要明确。

幸运的是,这很容易做到。 http://support.microsoft.com/kb/830033“rel=“noreferer” MS Knowledgebase。 该条中的法典(KB 830033)是trick的。

Alternative Managed API: A full wrapper for Vista s TaskDialog & TaskDialogIndirect can be found here:

http://code.msdn.icrosoft.com/WindowsAPICodePack

供世界森林论坛使用:

页: 1 一旦下载,该项目就会开放,然后加以建设(如果你想通过所有法典来审查图书馆或Interop文件夹中的档案)。 您现在可以从VistaBridgeindebug中拿到DL,并在你的项目中添加提及该DL的内容,而且你还必须用VistaBridge各单元的发言添加一个内容。 例:

利用Microsoft.SDK.Samples.VistaBridge.Interop或 .Library or .Properties or . Services - 视你们的需要而定。

VistaBridge项目包括许多其他Vistaites(如特工、Vista OpenFile和S SaveFile Dialogs,以及当然还有Aero玻璃效应)的APICS,以尝试这些节目,管理VistaBridge项目。

问题回答

任务方言的使用需要Windows Common Controls DL(ComCtl32.dll)第6版! 由于兼容性原因,申请没有因违约而受该版本的约束。 对第6版有约束力的一种办法是,在你可执行(称为“YouAppName.exe.mani)的同时,附上一份明确文件,内容如下:

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

如果你不希望获得额外的独立档案,也可将这一清单作为温32资源列入你可执行的(用RT_MANIFEST和IDP到1的名称)。 视像演播室可以为你做这项工作,如果你将你的明确档案与你的项目特性联系起来的话。

根据almog.ori的回答(涉及一些孤儿) 我对相关守则做了小小改动,我几天前pu:

MS Knowledgebase help (Archiv ), Full Code with adopteds made by me:

using System.Runtime.InteropServices;
using System;
using System.Security;
using System.Security.Permissions;
using System.Collections;
using System.IO;
using System.Text;

namespace MyOfficeNetAddin
{
    /// <devdoc>
    ///     This class is intended to use with the C#  using  statement in
    ///     to activate an activation context for turning on visual theming at
    ///     the beginning of a scope, and have it automatically deactivated
    ///     when the scope is exited.
    /// </devdoc>

[SuppressUnmanagedCodeSecurity]
internal class EnableThemingInScope : IDisposable
{
   // Private data
   private IntPtr cookie; // changed cookie from uint to IntPtr
   private static ACTCTX enableThemingActivationContext;
   private static IntPtr hActCtx;
   private static bool contextCreationSucceeded = false;

   public EnableThemingInScope(bool enable)
   {
     if (enable)
     {
       if (EnsureActivateContextCreated())
       {
         if (!ActivateActCtx(hActCtx, out cookie))
         {
           // Be sure cookie always zero if activation failed
           cookie = IntPtr.Zero;
         }
       }
     }
  }

  // Finalizer removed, that could cause Exceptions
  // ~EnableThemingInScope()
  // {
  //    Dispose(false);
  // }

  void IDisposable.Dispose()
  {
     Dispose(true);
     GC.SuppressFinalize(this);
  }

  private void Dispose(bool disposing)
  {
     if (cookie != IntPtr.Zero)
     {
        if (DeactivateActCtx(0, cookie))
        {
           // deactivation succeeded...
           cookie = IntPtr.Zero;
        }
     }
  }

  private bool EnsureActivateContextCreated()
  {
   lock (typeof(EnableThemingInScope))
   {
    if (!contextCreationSucceeded)
    {
     // Pull manifest from the .NET Framework install
     // directory

     string assemblyLoc = null;

     FileIOPermission fiop = new FileIOPermission(PermissionState.None);
     fiop.AllFiles = FileIOPermissionAccess.PathDiscovery;
     fiop.Assert();
     try
     {
        assemblyLoc = typeof(Object).Assembly.Location;
     }
     finally
     { 
        CodeAccessPermission.RevertAssert();
     }

     string manifestLoc = null;
     string installDir = null;
     if (assemblyLoc != null)
     {
        installDir = Path.GetDirectoryName(assemblyLoc);
        const string manifestName = "XPThemes.manifest";
        manifestLoc = Path.Combine(installDir, manifestName);
     }

     if (manifestLoc != null && installDir != null)
     {
         enableThemingActivationContext = new ACTCTX();
         enableThemingActivationContext.cbSize = Marshal.SizeOf(typeof(ACTCTX));
         enableThemingActivationContext.lpSource = manifestLoc;

         // Set the lpAssemblyDirectory to the install
         // directory to prevent Win32 Side by Side from
         // looking for comctl32 in the application
         // directory, which could cause a bogus dll to be
         // placed there and open a security hole.
         enableThemingActivationContext.lpAssemblyDirectory = installDir;
         enableThemingActivationContext.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID; 

         // Note this will fail gracefully if file specified
         // by manifestLoc doesn t exist.
         hActCtx = CreateActCtx(ref enableThemingActivationContext);
         contextCreationSucceeded = (hActCtx != new IntPtr(-1));
     }
    }

    // If we return false, we ll try again on the next call into
    // EnsureActivateContextCreated(), which is fine.
    return contextCreationSucceeded;
   }
  }

  // All the pinvoke goo...
  [DllImport("Kernel32.dll")]
  private extern static IntPtr CreateActCtx(ref ACTCTX actctx);

  // changed from uint to IntPtr according to 
  // https://www.pinvoke.net/default.aspx/kernel32.ActiveActCtx
  [DllImport("Kernel32.dll", SetLastError = true)]
  [return: MarshalAs(UnmanagedType.Bool)]
  private static extern bool ActivateActCtx(IntPtr hActCtx, out IntPtr lpCookie);

  // changed from uint to IntPtr according to 
  // https://www.pinvoke.net/default.aspx/kernel32.DeactivateActCtx
  [DllImport("Kernel32.dll", SetLastError = true)]
  [return: MarshalAs(UnmanagedType.Bool)]
  private static extern bool DeactivateActCtx(int dwFlags, IntPtr lpCookie);

  private const int ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID = 0x004;

  private struct ACTCTX 
  {
     public int       cbSize;
     public uint      dwFlags;
     public string    lpSource;
     public ushort    wProcessorArchitecture;
     public ushort    wLangId;
     public string    lpAssemblyDirectory;
     public string    lpResourceName;
     public string    lpApplicationName;
  }
 }
}

我随后使用了这一方法:

using (new EnableThemingInScope(true))
{
    // The call all this mucking about is here for.
    VistaUnsafeNativeMethods.TaskDialogIndirect(ref config, out result, out radioButtonResult, out verificationFlagChecked);
 }

。 WPF Task Dialog Wrapper on IX/

可在<条码>中查阅<>编码>。 见 Question on SO





相关问题
热门标签