Skip to content

Commit

Permalink
Merge pull request #532 from alesliehughes/master
Browse files Browse the repository at this point in the history
AxHost Changes
  • Loading branch information
marek-safar committed Jan 18, 2013
2 parents eaf26a5 + 37f035b commit 24a7d00
Showing 1 changed file with 62 additions and 11 deletions.
73 changes: 62 additions & 11 deletions mcs/class/Managed.Windows.Forms/System.Windows.Forms/AxHost.cs
Expand Up @@ -101,19 +101,30 @@ public void Disconnect ()

#region AxHost.InvalidActiveXStateException Class
public class InvalidActiveXStateException : Exception {
private string mName;
private ActiveXInvokeKind mKind;

public InvalidActiveXStateException ()
{
throw new NotImplementedException("COM/ActiveX support is not implemented");

}

public InvalidActiveXStateException (string name, ActiveXInvokeKind kind)
{
throw new NotImplementedException("COM/ActiveX support is not implemented");
mName = name;
mKind = kind;
}

public override string ToString ()
{
throw new NotImplementedException("COM/ActiveX support is not implemented");
if(mKind == ActiveXInvokeKind.MethodInvoke)
return "Invoke:" + mName;
else if(mKind == ActiveXInvokeKind.PropertyGet)
return "PropertyGet:" + mName;
else if(mKind == ActiveXInvokeKind.PropertySet)
return "PropertySet:" + mName;

return base.ToString();
}
}
#endregion // AxHost.InvalidActiveXStateException Class
Expand Down Expand Up @@ -185,23 +196,27 @@ public override object ConvertTo (ITypeDescriptorContext context, System.Globali
#endregion // AxHost Subclasses

//private int flags;
//private Guid clsid;
private Guid clsid;
private object instance;
private AboutBoxDelegate aboutDelegate = null;
private AxHost.State ocxState = null;
static bool runningOnWindows;

#region Protected Constructors

[MonoTODO]
protected AxHost (string clsid) : this(clsid, 0)
{

}

[MonoTODO]
protected AxHost (string clsid, int flags)
{
//this.clsid = new Guid(clsid);
this.clsid = new Guid(clsid);
//this.flags = flags;
this.instance = null;

PlatformID pid = Environment.OSVersion.Platform;
runningOnWindows = ((int) pid != 128 && (int) pid != 4 && (int) pid != 6);
}
#endregion // Public Instance Properties

Expand Down Expand Up @@ -507,7 +522,7 @@ public void EndInit ()
[EditorBrowsable (EditorBrowsableState.Advanced)]
public object GetOcx ()
{
throw new NotImplementedException("COM/ActiveX support is not implemented");
return instance;
}

public bool HasPropertyPages ()
Expand Down Expand Up @@ -552,20 +567,36 @@ public void ShowPropertyPages (Control control)
#region Protected Instance Methods
protected virtual void AttachInterfaces ()
{
throw new NotImplementedException("COM/ActiveX support is not implemented");

}

protected override void CreateHandle ()
{
if(!base.IsHandleCreated)
base.CreateHandle();
if(IsRunningOnWindows && !base.IsHandleCreated) {
GetActiveXInstance ();
AttachInterfaces ();

base.CreateHandle ();
} else {
throw new NotSupportedException ();
}
}

private void GetActiveXInstance()
{
if (this.instance == null) {
object obj;
CoCreateInstance (ref clsid, null, 1, ref IID_IUnknown, out obj);
this.instance = obj;
}
}

protected virtual object CreateInstanceCore (Guid clsid)
{
throw new NotImplementedException("COM/ActiveX support is not implemented");
}


[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void CreateSink ()
{
Expand All @@ -585,6 +616,11 @@ protected virtual void DetachSink ()

protected override void Dispose (bool disposing)
{
if(disposing) {
if(this.instance != null)
Marshal.ReleaseComObject (this.instance);
this.instance = null;
}
base.Dispose(disposing);
}

Expand Down Expand Up @@ -1072,5 +1108,20 @@ object ICustomTypeDescriptor.GetPropertyOwner (PropertyDescriptor pd)
throw new NotImplementedException("COM/ActiveX support is not implemented");
}
#endregion // Interfaces

internal static bool IsRunningOnWindows {
get { return runningOnWindows; }
}

static Guid IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046");

[DllImport("ole32.dll")]
static extern int CoCreateInstance (
[In] ref Guid rclsid,
[In, MarshalAs (UnmanagedType.IUnknown)] object pUnkOuter,
[In] uint dwClsContext,
[In] ref Guid riid,
[Out, MarshalAs (UnmanagedType.Interface)] out object ppv);

}
}

0 comments on commit 24a7d00

Please sign in to comment.