سؤال

I am writing an application and wanted to use the TaskDialogIndirect function - however I did not want to write a huge amount of P/Invoke stuff etc. so I have included the WinAPICodePack. There is one problem though! When I create a control for the TaskDialog and add it to the dialog everything works fine. However running the Show methods results in an OverflowException in mscorlib. I tracked this down to some pointer handling and marshalling.

Experimenting with the code had the result, that I found out, that the DLL MUST be compiled for .NET 3.5 and the including app TOO. Having my app on .NET 4.0 invokes this error... any idea about a workaround - or can you even reproduce this error?

Another issue is that I can set the the Icon property to whatevery I want, but the icon is not shown at all. I have to setup an Opened event which dynamically sets the icon...

Information: Running Visual Studio 2012 RTM on Windows 8 Pro x64 RTM. Application is a standard WPF app.

Sample code:

TaskDialog td = new TaskDialog();
td.Cancelable = true;
td.Caption = "Caption";
td.InstructionText = "Instructions";
td.Text = "Text";

TaskDialogCommandLink buttonElevation =
    new TaskDialogCommandLink("elevation", "Elevation Required Sample");
buttonElevation.UseElevationIcon = true;

td.Controls.Add(buttonElevation);
td.Show(); // OverflowException occurs here!
هل كانت مفيدة؟

المحلول

I fixed this issues which was basically a 32bit/64bit error. In the NativeTaskDialog.cs file there is one line critical, it's in the function

IntPtr AllocateAndMarshalButtons(
    TaskDialogNativeMethods.TaskDialogButton[] structs)

You need to locate the following line

 currentPtr = (IntPtr)((int)currentPtr + Marshal.SizeOf(button));

and replace it with

 currentPtr = (IntPtr)(currentPtr.ToInt64() + Marshal.SizeOf(button));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top