ActiveX control's constructor invokes second time
I have a couple of questions here related to IIS and ActiveX controls.
I am developing an activeX control by this tutorial
http://haseebakhtar.wordpress.com/2011/05/31/creating-an-activex-control-in-net-using-c/.
I am using IE9 for its testing and VS 2010 as IDE. Here is the code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;
namespace AxControls
{
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid("42BBA00A-515E-45b5-9EAF-3827F7AEB4FA")]
[ProgId("AxControls.HelloWorld")]
[ComDefaultInterface(typeof(IClip))]
public class HelloWorld : UserControl, IObjectSafety, IClip
{
public HelloWorld()
{
MessageBox.Show("Starting");
}
[STAThread]
public Image GetClipboardImage()
{
MessageBox.Show("try to get image");
Image returnImage = null;
if (Clipboard.ContainsImage())
{
MessageBox.Show("getting image");
returnImage = Clipboard.GetImage();
}
return returnImage;
}
private void SaveImage(Image image)
{
try
{
if (image != null)
{
MessageBox.Show("saving image");
image.Save("C:\\test.jpg");
}
}
catch (Exception e)
{
MessageBox.Show(e.StackTrace);
}
}
public void SaveImgFromClipBoard()
{
Image img = GetClipboardImage();
SaveImage(img);
}
#region IObjectSafety Members
public enum ObjectSafetyOptions
{
INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001,
INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002,
INTERFACE_USES_DISPEX = 0x00000004,
INTERFACE_USES_SECURITY_MANAGER = 0x00000008
};
public int GetInterfaceSafetyOptions(ref Guid riid, out int
pdwSupportedOptions, out int pdwEnabledOptions)
{
ObjectSafetyOptions m_options =
ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_CALLER |
ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_DATA;
pdwSupportedOptions = (int)m_options;
pdwEnabledOptions = (int)m_options;
return 0;
}
public int SetInterfaceSafetyOptions(ref Guid riid, int
dwOptionSetMask, int dwEnabledOptions)
{
return 0;
}
No comments:
Post a Comment