{"id":8304,"date":"2024-02-28T15:11:03","date_gmt":"2024-02-28T14:11:03","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=8304"},"modified":"2024-02-28T15:11:04","modified_gmt":"2024-02-28T14:11:04","slug":"unable-to-find-an-entry-point-named-taskdialogindirect-in-dll-comctl32","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/unable-to-find-an-entry-point-named-taskdialogindirect-in-dll-comctl32\/","title":{"rendered":"Unable to find an entry point named &#8216;TaskDialogIndirect&#8217; in DLL &#8216;ComCtl32&#8217;"},"content":{"rendered":"\n<p>Source: <a href=\"https:\/\/stackoverflow.com\/a\/54801782\">https:\/\/stackoverflow.com\/a\/54801782<\/a><\/p>\n\n\n\n<p><strong>Description<\/strong><br>The process is trying to display a &#8216;error&#8217; or &#8216;warning&#8217; dialog in a non-visual (win32\/native) context (e.g. a console app or windows service)<\/p>\n\n\n\n<p>In my case the dialog showed an error about an existing &#8216;.lock&#8217; file, preventing the process from continuing.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"csharp\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">\/\/\/ &lt;devdoc>\r\n\/\/\/     This class is intended to use with the C# 'using' statement in\r\n\/\/\/     to activate an activation context for turning on visual theming at\r\n\/\/\/     the beginning of a scope, and have it automatically deactivated\r\n\/\/\/     when the scope is exited.\r\n\/\/\/ &lt;\/devdoc>\r\n\r\n[SuppressUnmanagedCodeSecurity]\r\ninternal class EnableThemingInScope : IDisposable\r\n{\r\n   \/\/ Private data\r\n   private IntPtr cookie; \/\/ changed cookie from uint to IntPtr\r\n   private static ACTCTX enableThemingActivationContext;\r\n   private static IntPtr hActCtx;\r\n   private static bool contextCreationSucceeded = false;\r\n\r\n   public EnableThemingInScope(bool enable)\r\n   {\r\n     if (enable)\r\n     {\r\n       if (EnsureActivateContextCreated())\r\n       {\r\n         if (!ActivateActCtx(hActCtx, out cookie))\r\n         {\r\n           \/\/ Be sure cookie always zero if activation failed\r\n           cookie = IntPtr.Zero;\r\n         }\r\n       }\r\n     }\r\n  }\r\n\r\n  \/\/ Finalizer removed, that could cause Exceptions\r\n  \/\/ ~EnableThemingInScope()\r\n  \/\/ {\r\n  \/\/    Dispose(false);\r\n  \/\/ }\r\n\r\n  void IDisposable.Dispose()\r\n  {\r\n     Dispose(true);\r\n     GC.SuppressFinalize(this);\r\n  }\r\n\r\n  private void Dispose(bool disposing)\r\n  {\r\n     if (cookie != IntPtr.Zero)\r\n     {\r\n        if (DeactivateActCtx(0, cookie))\r\n        {\r\n           \/\/ deactivation succeeded...\r\n           cookie = IntPtr.Zero;\r\n        }\r\n     }\r\n  }\r\n\r\n  private bool EnsureActivateContextCreated()\r\n  {\r\n   lock (typeof(EnableThemingInScope))\r\n   {\r\n    if (!contextCreationSucceeded)\r\n    {\r\n     \/\/ Pull manifest from the .NET Framework install\r\n     \/\/ directory\r\n\r\n     string assemblyLoc = null;\r\n\r\n     FileIOPermission fiop = new FileIOPermission(PermissionState.None);\r\n     fiop.AllFiles = FileIOPermissionAccess.PathDiscovery;\r\n     fiop.Assert();\r\n     try\r\n     {\r\n        assemblyLoc = typeof(Object).Assembly.Location;\r\n     }\r\n     finally\r\n     { \r\n        CodeAccessPermission.RevertAssert();\r\n     }\r\n\r\n     string manifestLoc = null;\r\n     string installDir = null;\r\n     if (assemblyLoc != null)\r\n     {\r\n        installDir = Path.GetDirectoryName(assemblyLoc);\r\n        const string manifestName = \"XPThemes.manifest\";\r\n        manifestLoc = Path.Combine(installDir, manifestName);\r\n     }\r\n\r\n     if (manifestLoc != null &amp;&amp; installDir != null)\r\n     {\r\n         enableThemingActivationContext = new ACTCTX();\r\n         enableThemingActivationContext.cbSize = Marshal.SizeOf(typeof(ACTCTX));\r\n         enableThemingActivationContext.lpSource = manifestLoc;\r\n\r\n         \/\/ Set the lpAssemblyDirectory to the install\r\n         \/\/ directory to prevent Win32 Side by Side from\r\n         \/\/ looking for comctl32 in the application\r\n         \/\/ directory, which could cause a bogus dll to be\r\n         \/\/ placed there and open a security hole.\r\n         enableThemingActivationContext.lpAssemblyDirectory = installDir;\r\n         enableThemingActivationContext.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID; \r\n\r\n         \/\/ Note this will fail gracefully if file specified\r\n         \/\/ by manifestLoc doesn't exist.\r\n         hActCtx = CreateActCtx(ref enableThemingActivationContext);\r\n         contextCreationSucceeded = (hActCtx != new IntPtr(-1));\r\n     }\r\n    }\r\n\r\n    \/\/ If we return false, we'll try again on the next call into\r\n    \/\/ EnsureActivateContextCreated(), which is fine.\r\n    return contextCreationSucceeded;\r\n   }\r\n  }\r\n\r\n  \/\/ All the pinvoke goo...\r\n  [DllImport(\"Kernel32.dll\")]\r\n  private extern static IntPtr CreateActCtx(ref ACTCTX actctx);\r\n\r\n  \/\/ changed from uint to IntPtr according to \r\n  \/\/ https:\/\/www.pinvoke.net\/default.aspx\/kernel32.ActiveActCtx\r\n  [DllImport(\"Kernel32.dll\", SetLastError = true)]\r\n  [return: MarshalAs(UnmanagedType.Bool)]\r\n  private static extern bool ActivateActCtx(IntPtr hActCtx, out IntPtr lpCookie);\r\n\r\n  \/\/ changed from uint to IntPtr according to \r\n  \/\/ https:\/\/www.pinvoke.net\/default.aspx\/kernel32.DeactivateActCtx\r\n  [DllImport(\"Kernel32.dll\", SetLastError = true)]\r\n  [return: MarshalAs(UnmanagedType.Bool)]\r\n  private static extern bool DeactivateActCtx(int dwFlags, IntPtr lpCookie);\r\n\r\n  private const int ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID = 0x004;\r\n\r\n  private struct ACTCTX \r\n  {\r\n     public int       cbSize;\r\n     public uint      dwFlags;\r\n     public string    lpSource;\r\n     public ushort    wProcessorArchitecture;\r\n     public ushort    wLangId;\r\n     public string    lpAssemblyDirectory;\r\n     public string    lpResourceName;\r\n     public string    lpApplicationName;\r\n  }\r\n }\r\n}<\/pre><\/div>\n\n\n\n<p>Example:<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"csharp\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">using (new EnableThemingInScope(true))\r\n{\r\n    \/\/ The call all this mucking about is here for.\r\n    VistaUnsafeNativeMethods.TaskDialogIndirect(ref config, out result, out radioButtonResult, out verificationFlagChecked);\r\n }<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/stackoverflow.com\/a\/54801782 DescriptionThe process is trying to display a &#8216;error&#8217; or &#8216;warning&#8217; dialog in a non-visual (win32\/native) context (e.g. a console app or windows service) In my case the dialog showed an error about an existing &#8216;.lock&#8217; file, preventing the process from continuing. Example:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8304","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/8304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=8304"}],"version-history":[{"count":1,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/8304\/revisions"}],"predecessor-version":[{"id":8305,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/8304\/revisions\/8305"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=8304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=8304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=8304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}