Question

Let me give a full explanation of my scenario:

We are required to use a signature pad in our application, which is being developed in Silverlight 5, in Out-Of-Browser mode, with elevated trust, the problem starts with the fact that the device manufacturer doesn't provide any kind of API or SDK for Silverlight, their .NET assembly actually is for WinForms applications, but it's still usable in WPF by putting the control in a WindowsFormHost.

I've been looking for options and so far we have 2 alternatives, both of which involve creating a small WPF app to use the control and capture the signature there, calling it from Silverlight:

  1. Create a "listener" that checks the folder in which the signature is saved as an image and send it to the silverlight application.
  2. Have the Silverlight app get the file itself, the user would have to click a button for this.

I would prefer to do this by retrieveing the result from the WPF app itself, I tried to do it using COM but couldn't do it.

I can do one of those things at a time (launching OR getting the result from another assembly) but not both.

I followed this article to use COM in Silverlight, and this one to give the assembly a strong name, along with this one to launch another application using COM Interoperability.

The WPF app is launched as described in the link above (using WScript.Shell Run method), and I have the following class in that very same .exe file

namespace WpfSignatureCapture
{
  [ProgId("WpfSignatureCapture")]
  [ClassInterface(ClassInterfaceType.AutoDual)]
  static public class ImageExport
  {
    private static byte[] image;
    public static byte[] Image { get; set; }

    [ComVisible(true)]
    public static byte[] ImageAsByteArray()
    {
        return image;
    }
  }
}

For reference, after the signature is captured, the user should click a button to save it as an image, which executes the next method:

    private void SaveToImage_Click(object sender, RoutedEventArgs e)
    {
        var img = sigPlusNET.GetSigImage();
        var ms = new MemoryStream();
        img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
        byte[] array = ms.ToArray();

        ImageExport.Image = array;
    }

When I try to get that byte array from the WPF app still running, there doesn't seem to be able to find the ProgId even though I signed and registered the WPF app's exe.

This is how I attempt to get it:

    private void GetSignatureClick(object sender, RoutedEventArgs e)
    {
        byte[] image;

        if (Application.Current.HasElevatedPermissions && AutomationFactory.IsAvailable)
        {
            dynamic getImage = AutomationFactory.GetObject("WpfSignatureCapture");

            image = getImage.ImageAsByteArray();
            var file = new FileStream(@"C:\signature.bmp", FileMode.Create);
            file.Write(image, 0, image.Length);
            file.Flush();
            file.Close();
        }
    }

And this is the error I get:

enter image description here

So I have three questions:

  1. Is what I'm trying to do possible?
  2. What approach should I take for this to work?
  3. Are there any other simpler/more efficient ways to do this? if so, how?
Was it helpful?

Solution

Between Silverlight apps, I'd suggest using local inter-process communication - see http://msdn.microsoft.com/en-us/library/dd833063%28v=VS.95%29.aspx - but it would probably not work between Silverlight and WPF.

So, the remaining option is to have a file/directory that is known to both applications and that is polled or monitored for changes by the apps - see http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher%28v=vs.110%29.aspx for monitoring.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top