public int CreateInstance(IntPtr unkOuter, ref Guid iid, out IntPtr obj) { obj = IntPtr.Zero; if (unkOuter != IntPtr.Zero) { Marshal.ThrowExceptionForHR(NativeMethods.CLASS_E_NOAGGREGATION); } else if (iid == NativeMethods.iidIUnknown || iid == typeof(IPropertyPage).GUID) { // Create the PropertyPagePane from the clsid IntPtr paneUnknown; int hr = NativeMethods.CoCreateInstance(ref clsid, unkOuter, NativeMethods.CLSCTX_INPROC_SERVER, ref iid, out paneUnknown); if (hr != 0) { Marshal.ThrowExceptionForHR(hr); } else { // Marshal it into a C# object IPropertyPane pane = Marshal.GetTypedObjectForIUnknown(paneUnknown, typeof(IPropertyPane)) as IPropertyPane; if (pane == null) { Marshal.ThrowExceptionForHR(NativeMethods.E_NOINTERFACE); } else { // Create a property page from the property page pane. IPropertyPage page = new PropertyPage(pane); // And marshall the property page back to an IPropertyPage COM interface obj = Marshal.GetComInterfaceForObject(page, typeof(IPropertyPage)); } } } else { Marshal.ThrowExceptionForHR(NativeMethods.E_NOINTERFACE); } return(0); }
public int CreateInstance(IntPtr unkOuter, ref Guid iid, out IntPtr obj) { obj = IntPtr.Zero; if (unkOuter != IntPtr.Zero) { Marshal.ThrowExceptionForHR(NativeMethods.CLASS_E_NOAGGREGATION); } else if (iid == NativeMethods.iidIUnknown || iid == typeof(IPropertyPage).GUID) { // Create the PropertyPagePane from the clsid IntPtr paneUnknown; int hr = NativeMethods.CoCreateInstance(ref clsid, unkOuter, NativeMethods.CLSCTX_INPROC_SERVER, ref iid, out paneUnknown); if (hr != 0) Marshal.ThrowExceptionForHR(hr); else { // Marshal it into a C# object IPropertyPane pane = Marshal.GetTypedObjectForIUnknown(paneUnknown, typeof(IPropertyPane)) as IPropertyPane; if (pane == null) { Marshal.ThrowExceptionForHR(NativeMethods.E_NOINTERFACE); } else { // Create a property page from the property page pane. IPropertyPage page = new PropertyPage(pane); // And marshall the property page back to an IPropertyPage COM interface obj = Marshal.GetComInterfaceForObject(page, typeof(IPropertyPage)); } } } else { Marshal.ThrowExceptionForHR(NativeMethods.E_NOINTERFACE); } return 0; }