internal ComponentManagerProxy(ComponentManagerBroker broker, UnsafeNativeMethods.IMsoComponentManager original) { this._broker = broker; this._original = original; this._creationThread = SafeNativeMethods.GetCurrentThreadId(); this._refCount = 0; }
int UnsafeNativeMethods.IOleDropTarget.OleDragOver(int grfKeyState, UnsafeNativeMethods.POINTSTRUCT pt, ref int pdwEffect) { Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "OleDragOver recieved"); NativeMethods.POINTL ptl = new NativeMethods.POINTL(); ptl.x = pt.x; ptl.y = pt.y; Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "\t" + (ptl.x) + "," + (ptl.y)); DragEventArgs drgevent = CreateDragEventArgs(null, grfKeyState, ptl, pdwEffect); owner.OnDragOver(drgevent); pdwEffect = (int)drgevent.Effect; lastEffect = drgevent.Effect; return NativeMethods.S_OK; }
int UnsafeNativeMethods.IOleDropTarget.OleDragEnter(object pDataObj, int grfKeyState, UnsafeNativeMethods.POINTSTRUCT pt, ref int pdwEffect) { Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "OleDragEnter recieved"); NativeMethods.POINTL ptl = new NativeMethods.POINTL(); ptl.x = pt.x; ptl.y = pt.y; Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "\t" + (ptl.x) + "," + (ptl.y)); Debug.Assert(pDataObj != null, "OleDragEnter didn't give us a valid data object."); DragEventArgs drgevent = CreateDragEventArgs(pDataObj, grfKeyState, ptl, pdwEffect); if (drgevent != null) { owner.OnDragEnter(drgevent); pdwEffect = (int)drgevent.Effect; lastEffect = drgevent.Effect; } else { pdwEffect = (int)DragDropEffects.None; } return NativeMethods.S_OK; }
bool UnsafeNativeMethods.IMsoComponentManager.FGetActiveComponent(int dwgac, UnsafeNativeMethods.IMsoComponent[] ppic, System.Windows.Forms.NativeMethods.MSOCRINFOSTRUCT info, int dwReserved) { if (this._original == null) { return false; } if (!this._original.FGetActiveComponent(dwgac, ppic, info, dwReserved)) { return false; } if (ppic[0] == this) { if (dwgac == 0) { ppic[0] = this._activeComponent; } else if (dwgac == 1) { ppic[0] = this._trackingComponent; } else if ((dwgac == 2) && (this._trackingComponent != null)) { ppic[0] = this._trackingComponent; } } return (ppic[0] != null); }
int UnsafeNativeMethods.IOleInPlaceSite.GetWindowContext(out UnsafeNativeMethods.IOleInPlaceFrame ppFrame, out UnsafeNativeMethods.IOleInPlaceUIWindow ppDoc, System.Windows.Forms.NativeMethods.COMRECT lprcPosRect, System.Windows.Forms.NativeMethods.COMRECT lprcClipRect, System.Windows.Forms.NativeMethods.tagOIFI lpFrameInfo) { ppDoc = null; ppFrame = this.Host.GetParentContainer(); lprcPosRect.left = this.Host.Bounds.X; lprcPosRect.top = this.Host.Bounds.Y; lprcPosRect.right = this.Host.Bounds.Width + this.Host.Bounds.X; lprcPosRect.bottom = this.Host.Bounds.Height + this.Host.Bounds.Y; lprcClipRect = WebBrowserHelper.GetClipRect(); if (lpFrameInfo != null) { lpFrameInfo.cb = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.tagOIFI)); lpFrameInfo.fMDIApp = false; lpFrameInfo.hAccel = IntPtr.Zero; lpFrameInfo.cAccelEntries = 0; lpFrameInfo.hwndFrame = (this.Host.ParentInternal == null) ? IntPtr.Zero : this.Host.ParentInternal.Handle; } return 0; }
int UnsafeNativeMethods.IOleInPlaceFrame.SetActiveObject(UnsafeNativeMethods.IOleInPlaceActiveObject pActiveObject, string pszObjName) { if (pActiveObject == null) { if (this.ctlInEditMode != null) { this.ctlInEditMode.SetEditMode(WebBrowserHelper.AXEditMode.None); this.ctlInEditMode = null; } return 0; } WebBrowserBase aXHost = null; UnsafeNativeMethods.IOleObject obj2 = pActiveObject as UnsafeNativeMethods.IOleObject; if (obj2 != null) { try { WebBrowserSiteBase clientSite = obj2.GetClientSite() as WebBrowserSiteBase; if (clientSite != null) { aXHost = clientSite.GetAXHost(); } } catch (COMException) { } if (this.ctlInEditMode != null) { this.ctlInEditMode.SetSelectionStyle(WebBrowserHelper.SelectionStyle.Selected); this.ctlInEditMode.SetEditMode(WebBrowserHelper.AXEditMode.None); } if (aXHost == null) { this.ctlInEditMode = null; } else if (!aXHost.IsUserMode) { this.ctlInEditMode = aXHost; aXHost.SetEditMode(WebBrowserHelper.AXEditMode.Object); aXHost.AddSelectionHandler(); aXHost.SetSelectionStyle(WebBrowserHelper.SelectionStyle.Active); } } return 0; }
internal HtmlWindowCollection(HtmlShimManager shimManager, UnsafeNativeMethods.IHTMLFramesCollection2 collection) { this.htmlFramesCollection2 = collection; this.shimManager = shimManager; }
private static Guid GetGuidForTypeInfo(UnsafeNativeMethods.ITypeInfo typeInfo, StructCache structCache, int[] versions) { IntPtr zero = IntPtr.Zero; int typeAttr = typeInfo.GetTypeAttr(ref zero); if (!System.Windows.Forms.NativeMethods.Succeeded(typeAttr)) { throw new ExternalException(System.Windows.Forms.SR.GetString("TYPEINFOPROCESSORGetTypeAttrFailed", new object[] { typeAttr }), typeAttr); } Guid empty = Guid.Empty; System.Windows.Forms.NativeMethods.tagTYPEATTR data = null; try { if (structCache == null) { data = new System.Windows.Forms.NativeMethods.tagTYPEATTR(); } else { data = (System.Windows.Forms.NativeMethods.tagTYPEATTR) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagTYPEATTR)); } UnsafeNativeMethods.PtrToStructure(zero, data); empty = data.guid; if (versions != null) { versions[0] = data.wMajorVerNum; versions[1] = data.wMinorVerNum; } } finally { typeInfo.ReleaseTypeAttr(zero); if ((structCache != null) && (data != null)) { structCache.ReleaseStruct(data); } } return empty; }
private static System.Type ProcessTypeInfoEnum(UnsafeNativeMethods.ITypeInfo enumTypeInfo, StructCache structCache) { if (enumTypeInfo != null) { try { IntPtr zero = IntPtr.Zero; int typeAttr = enumTypeInfo.GetTypeAttr(ref zero); if (!System.Windows.Forms.NativeMethods.Succeeded(typeAttr) || (zero == IntPtr.Zero)) { throw new ExternalException(System.Windows.Forms.SR.GetString("TYPEINFOPROCESSORGetTypeAttrFailed", new object[] { typeAttr }), typeAttr); } System.Windows.Forms.NativeMethods.tagTYPEATTR data = (System.Windows.Forms.NativeMethods.tagTYPEATTR) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagTYPEATTR)); UnsafeNativeMethods.PtrToStructure(zero, data); if (zero == IntPtr.Zero) { return null; } try { int cVars = data.cVars; ArrayList list = new ArrayList(); ArrayList list2 = new ArrayList(); System.Windows.Forms.NativeMethods.tagVARDESC gvardesc = (System.Windows.Forms.NativeMethods.tagVARDESC) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagVARDESC)); object objectForNativeVariant = null; string pBstrName = null; string pBstrDocString = null; enumTypeInfo.GetDocumentation(-1, ref pBstrName, ref pBstrDocString, null, null); for (int i = 0; i < cVars; i++) { IntPtr pVarDesc = IntPtr.Zero; if (System.Windows.Forms.NativeMethods.Succeeded(enumTypeInfo.GetVarDesc(i, ref pVarDesc)) && (pVarDesc != IntPtr.Zero)) { try { UnsafeNativeMethods.PtrToStructure(pVarDesc, gvardesc); if (((gvardesc != null) && (gvardesc.varkind == 2)) && (gvardesc.unionMember != IntPtr.Zero)) { str2 = (string) (pBstrDocString = null); objectForNativeVariant = null; if (System.Windows.Forms.NativeMethods.Succeeded(enumTypeInfo.GetDocumentation(gvardesc.memid, null, ref pBstrDocString, null, null))) { string str4; try { objectForNativeVariant = Marshal.GetObjectForNativeVariant(gvardesc.unionMember); } catch (Exception) { } list2.Add(objectForNativeVariant); if (pBstrDocString != null) { str4 = pBstrDocString; } else { str4 = str2; } list.Add(str4); } } } finally { if (pVarDesc != IntPtr.Zero) { enumTypeInfo.ReleaseVarDesc(pVarDesc); } } } } structCache.ReleaseStruct(gvardesc); if (list.Count > 0) { IntPtr iUnknownForObject = Marshal.GetIUnknownForObject(enumTypeInfo); try { pBstrName = iUnknownForObject.ToString() + "_" + pBstrName; if (builtEnums == null) { builtEnums = new Hashtable(); } else if (builtEnums.ContainsKey(pBstrName)) { return (System.Type) builtEnums[pBstrName]; } System.Type underlyingType = typeof(int); if ((list2.Count > 0) && (list2[0] != null)) { underlyingType = list2[0].GetType(); } EnumBuilder builder = ModuleBuilder.DefineEnum(pBstrName, TypeAttributes.Public, underlyingType); for (int j = 0; j < list.Count; j++) { builder.DefineLiteral((string) list[j], list2[j]); } System.Type type2 = builder.CreateType(); builtEnums[pBstrName] = type2; return type2; } finally { if (iUnknownForObject != IntPtr.Zero) { Marshal.Release(iUnknownForObject); } } } } finally { enumTypeInfo.ReleaseTypeAttr(zero); structCache.ReleaseStruct(data); } } catch { } } return null; }
private static PropInfo ProcessDataCore(UnsafeNativeMethods.ITypeInfo typeInfo, IDictionary propInfoList, int dispid, int nameDispID, System.Windows.Forms.NativeMethods.tagTYPEDESC typeDesc, int flags, StructCache structCache) { string pBstrName = null; string pBstrDocString = null; int hr = typeInfo.GetDocumentation(dispid, ref pBstrName, ref pBstrDocString, null, null); ComNativeDescriptor instance = ComNativeDescriptor.Instance; if (!System.Windows.Forms.NativeMethods.Succeeded(hr)) { throw new COMException(System.Windows.Forms.SR.GetString("TYPEINFOPROCESSORGetDocumentationFailed", new object[] { dispid, hr, instance.GetClassName(typeInfo) }), hr); } if (pBstrName == null) { return null; } PropInfo info = (PropInfo) propInfoList[pBstrName]; if (info == null) { info = new PropInfo { Index = propInfoList.Count }; propInfoList[pBstrName] = info; info.Name = pBstrName; info.DispId = dispid; info.Attributes.Add(new DispIdAttribute(info.DispId)); } if (pBstrDocString != null) { info.Attributes.Add(new DescriptionAttribute(pBstrDocString)); } if (info.ValueType == null) { object[] typeData = new object[1]; try { info.ValueType = GetValueTypeFromTypeDesc(typeDesc, typeInfo, typeData, structCache); } catch (Exception) { } if (info.ValueType == null) { info.NonBrowsable = true; } if (info.NonBrowsable) { flags |= 0x400; } if (typeData[0] != null) { info.TypeData = typeData[0]; } } if ((flags & 1) != 0) { info.ReadOnly = 1; } if ((((flags & 0x40) != 0) || ((flags & 0x400) != 0)) || ((info.Name[0] == '_') || (dispid == -515))) { info.Attributes.Add(new BrowsableAttribute(false)); info.NonBrowsable = true; } if ((flags & 0x200) != 0) { info.IsDefault = true; } if (((flags & 4) != 0) && ((flags & 0x10) != 0)) { info.Attributes.Add(new BindableAttribute(true)); } if (dispid == nameDispID) { info.Attributes.Add(new ParenthesizePropertyNameAttribute(true)); info.Attributes.Add(new MergablePropertyAttribute(false)); } return info; }
protected virtual IntPtr CreateMenuHandle() { return(UnsafeNativeMethods.CreatePopupMenu()); }
/// <include file='doc\StatusBarPanel.uex' path='docs/doc[@for="StatusBarPanel.Realize"]/*' /> /// <internalonly/> /// <devdoc> /// Sets all the properties for this panel. /// </devdoc> internal void Realize() { if (Created) { string text; string sendText; int border = 0; if (this.text == null) { text = ""; } else { text = this.text; } HorizontalAlignment align = alignment; // Translate the alignment for Rtl apps // if (parent.RightToLeft == RightToLeft.Yes) { switch (align) { case HorizontalAlignment.Left: align = HorizontalAlignment.Right; break; case HorizontalAlignment.Right: align = HorizontalAlignment.Left; break; } } switch (align) { case HorizontalAlignment.Center: sendText = "\t" + text; break; case HorizontalAlignment.Right: sendText = "\t\t" + text; break; default: sendText = text; break; } switch (borderStyle) { case StatusBarPanelBorderStyle.None: border |= NativeMethods.SBT_NOBORDERS; break; case StatusBarPanelBorderStyle.Sunken: break; case StatusBarPanelBorderStyle.Raised: border |= NativeMethods.SBT_POPOUT; break; } switch (style) { case StatusBarPanelStyle.Text: break; case StatusBarPanelStyle.OwnerDraw: border |= NativeMethods.SBT_OWNERDRAW; break; } int wparam = GetIndex() | border; if (parent.RightToLeft == RightToLeft.Yes) { wparam |= NativeMethods.SBT_RTLREADING; } int result = (int)UnsafeNativeMethods.SendMessage(new HandleRef(parent, parent.Handle), NativeMethods.SB_SETTEXT, (IntPtr)wparam, sendText); if (result == 0) { throw new InvalidOperationException(SR.UnableToSetPanelText); } if (this.icon != null && style != StatusBarPanelStyle.OwnerDraw) { this.parent.SendMessage(NativeMethods.SB_SETICON, (IntPtr)GetIndex(), this.icon.Handle); } else { this.parent.SendMessage(NativeMethods.SB_SETICON, (IntPtr)GetIndex(), IntPtr.Zero); } if (style == StatusBarPanelStyle.OwnerDraw) { NativeMethods.RECT rect = new NativeMethods.RECT(); result = (int)UnsafeNativeMethods.SendMessage(new HandleRef(parent, parent.Handle), NativeMethods.SB_GETRECT, (IntPtr)GetIndex(), ref rect); if (result != 0) { this.parent.Invalidate(Rectangle.FromLTRB(rect.left, rect.top, rect.right, rect.bottom)); } } } }
/// <include file='doc\Help.uex' path='docs/doc[@for="Help.ShowHTML10Help"]/*' /> /// <devdoc> /// Displays HTML 1.0 Help with the specified parameters /// </devdoc> /// <internalonly/> private static void ShowHTML10Help(Control parent, string url, HelpNavigator command, object param) { Debug.WriteLineIf(Help.WindowsFormsHelpTrace.TraceVerbose, "Help:: ShowHTML10Help:: " + url + ", " + command.ToString("G") + ", " + param); IntSecurity.UnmanagedCode.Demand(); // See if we can get a full path and file name and if that will // resolve the out of memory condition with file names that include spaces. // If we can't, though, we can't assume that the path's no good: it might be in // the Windows help directory. Uri file = null; string pathAndFileName = url; //This is our best guess at the path yet. file = Resolve(url); if (file != null) // Can't assume we have a good url { pathAndFileName = file.AbsoluteUri; } if (file == null || file.IsFile) { StringBuilder newPath = new StringBuilder(); string localPath = (file != null && file.IsFile) ? file.LocalPath : url; // If this is a local path, convert it to a short path name. Pass 0 as the length the first time uint requiredStringSize = UnsafeNativeMethods.GetShortPathName(localPath, newPath, 0); if (requiredStringSize > 0) { //It's able to make it a short path. Happy day. newPath.Capacity = (int)requiredStringSize; requiredStringSize = UnsafeNativeMethods.GetShortPathName(localPath, newPath, requiredStringSize); //If it can't make it a short path, just leave the path we had. pathAndFileName = newPath.ToString(); } } HandleRef handle; if (parent != null) { handle = new HandleRef(parent, parent.Handle); } else { handle = new HandleRef(null, UnsafeNativeMethods.GetActiveWindow()); } object htmlParam; string stringParam = param as string; if (stringParam != null) { int htmlCommand = MapCommandToHTMLCommand(command, stringParam, out htmlParam); string stringHtmlParam = htmlParam as string; if (stringHtmlParam != null) { SafeNativeMethods.HtmlHelp(handle, pathAndFileName, htmlCommand, stringHtmlParam); } else if (htmlParam is int) { SafeNativeMethods.HtmlHelp(handle, pathAndFileName, htmlCommand, (int)htmlParam); } else if (htmlParam is NativeMethods.HH_FTS_QUERY) { SafeNativeMethods.HtmlHelp(handle, pathAndFileName, htmlCommand, (NativeMethods.HH_FTS_QUERY)htmlParam); } else if (htmlParam is NativeMethods.HH_AKLINK) { // According to MSDN documentation, we have to ensure that the help window is up // before we call ALINK lookup. // SafeNativeMethods.HtmlHelp(NativeMethods.NullHandleRef, pathAndFileName, HH_DISPLAY_TOPIC, (string)null); SafeNativeMethods.HtmlHelp(handle, pathAndFileName, htmlCommand, (NativeMethods.HH_AKLINK)htmlParam); } else { Debug.Fail("Cannot handle HTML parameter of type: " + htmlParam.GetType()); SafeNativeMethods.HtmlHelp(handle, pathAndFileName, htmlCommand, (string)param); } } else if (param == null) { SafeNativeMethods.HtmlHelp(handle, pathAndFileName, MapCommandToHTMLCommand(command, null, out htmlParam), 0); } else if (param is NativeMethods.HH_POPUP) { SafeNativeMethods.HtmlHelp(handle, pathAndFileName, HH_DISPLAY_TEXT_POPUP, (NativeMethods.HH_POPUP)param); } else if (param.GetType() == typeof(Int32)) { throw new ArgumentException(string.Format(SR.InvalidArgument, "param", "Integer")); } }
// Due to the nature of PRINTDLGEX vs PRINTDLG, separate but similar methods // are required for showing the print dialog on Win2k and newer OS'. private bool ShowPrintDialog(IntPtr hwndOwner, NativeMethods.PRINTDLGEX data) { data.Flags = GetFlags(); data.nCopies = PrinterSettings.Copies; data.hwndOwner = hwndOwner; try { if (PageSettings == null) { data.hDevMode = PrinterSettings.GetHdevmode(); } else { data.hDevMode = PrinterSettings.GetHdevmode(PageSettings); } data.hDevNames = PrinterSettings.GetHdevnames(); } catch (InvalidPrinterException) { data.hDevMode = IntPtr.Zero; data.hDevNames = IntPtr.Zero; // Leave those fields null; Windows will fill them in } try { // Windows doesn't like it if page numbers are invalid if (AllowSomePages) { if (PrinterSettings.FromPage < PrinterSettings.MinimumPage || PrinterSettings.FromPage > PrinterSettings.MaximumPage) { throw new ArgumentException(string.Format(SR.PDpageOutOfRange, "FromPage")); } if (PrinterSettings.ToPage < PrinterSettings.MinimumPage || PrinterSettings.ToPage > PrinterSettings.MaximumPage) { throw new ArgumentException(string.Format(SR.PDpageOutOfRange, "ToPage")); } if (PrinterSettings.ToPage < PrinterSettings.FromPage) { throw new ArgumentException(string.Format(SR.PDpageOutOfRange, "FromPage")); } unsafe { int *pageRangeField = (int *)data.pageRanges; * pageRangeField = PrinterSettings.FromPage; pageRangeField += 1; *pageRangeField = PrinterSettings.ToPage; } data.nPageRanges = 1; data.nMinPage = PrinterSettings.MinimumPage; data.nMaxPage = PrinterSettings.MaximumPage; } // // The flags NativeMethods.PD_SHOWHELP and NativeMethods.PD_NONETWORKBUTTON don't work with // PrintDlgEx. So we have to strip them out. data.Flags &= ~(PD.SHOWHELP | PD.NONETWORKBUTTON); int hr = UnsafeNativeMethods.PrintDlgEx(data); if (NativeMethods.Failed(hr) || data.dwResultAction == PD_RESULT.CANCEL) { return(false); } UpdatePrinterSettings(data.hDevMode, data.hDevNames, (short)data.nCopies, data.Flags, PrinterSettings, PageSettings); PrintToFile = (data.Flags & PD.PRINTTOFILE) != 0; PrinterSettings.PrintToFile = PrintToFile; if (AllowSomePages) { unsafe { int *pageRangeField = (int *)data.pageRanges; PrinterSettings.FromPage = *pageRangeField; pageRangeField += 1; PrinterSettings.ToPage = *pageRangeField; } } // When the flag PD_USEDEVMODECOPIESANDCOLLATE is not set, // PRINTDLG.nCopies or PRINTDLG.nCopies indicates the number of copies the user wants // to print, and the PD_COLLATE flag in the Flags member indicates // whether the user wants to print them collated. if ((data.Flags & PD.USEDEVMODECOPIESANDCOLLATE) == 0) { PrinterSettings.Copies = (short)(data.nCopies); PrinterSettings.Collate = (data.Flags & PD.COLLATE) == PD.COLLATE; } // We should return true only if the user pressed the "Print" button while dismissing the dialog. return(data.dwResultAction == PD_RESULT.PRINT); } finally { if (data.hDevMode != IntPtr.Zero) { Kernel32.GlobalFree(data.hDevMode); } if (data.hDevNames != IntPtr.Zero) { Kernel32.GlobalFree(data.hDevNames); } if (data.pageRanges != IntPtr.Zero) { Kernel32.GlobalFree(data.pageRanges); } } }
private bool ShowPrintDialog(IntPtr hwndOwner, NativeMethods.WndProc hookProcPtr, NativeMethods.PRINTDLG data) { data.Flags = GetFlags(); data.nCopies = (short)PrinterSettings.Copies; data.hwndOwner = hwndOwner; data.lpfnPrintHook = hookProcPtr; try { if (PageSettings == null) { data.hDevMode = PrinterSettings.GetHdevmode(); } else { data.hDevMode = PrinterSettings.GetHdevmode(PageSettings); } data.hDevNames = PrinterSettings.GetHdevnames(); } catch (InvalidPrinterException) { data.hDevMode = IntPtr.Zero; data.hDevNames = IntPtr.Zero; // Leave those fields null; Windows will fill them in } try { // Windows doesn't like it if page numbers are invalid if (AllowSomePages) { if (PrinterSettings.FromPage < PrinterSettings.MinimumPage || PrinterSettings.FromPage > PrinterSettings.MaximumPage) { throw new ArgumentException(string.Format(SR.PDpageOutOfRange, "FromPage")); } if (PrinterSettings.ToPage < PrinterSettings.MinimumPage || PrinterSettings.ToPage > PrinterSettings.MaximumPage) { throw new ArgumentException(string.Format(SR.PDpageOutOfRange, "ToPage")); } if (PrinterSettings.ToPage < PrinterSettings.FromPage) { throw new ArgumentException(string.Format(SR.PDpageOutOfRange, "FromPage")); } data.nFromPage = (short)PrinterSettings.FromPage; data.nToPage = (short)PrinterSettings.ToPage; data.nMinPage = (short)PrinterSettings.MinimumPage; data.nMaxPage = (short)PrinterSettings.MaximumPage; } if (!UnsafeNativeMethods.PrintDlg(data)) { return(false); } UpdatePrinterSettings(data.hDevMode, data.hDevNames, data.nCopies, data.Flags, settings, PageSettings); PrintToFile = (data.Flags & PD.PRINTTOFILE) != 0; PrinterSettings.PrintToFile = PrintToFile; if (AllowSomePages) { PrinterSettings.FromPage = data.nFromPage; PrinterSettings.ToPage = data.nToPage; } // When the flag PD_USEDEVMODECOPIESANDCOLLATE is not set, // PRINTDLG.nCopies or PRINTDLG.nCopies indicates the number of copies the user wants // to print, and the PD_COLLATE flag in the Flags member indicates // whether the user wants to print them collated. if ((data.Flags & PD.USEDEVMODECOPIESANDCOLLATE) == 0) { PrinterSettings.Copies = data.nCopies; PrinterSettings.Collate = (data.Flags & PD.COLLATE) == PD.COLLATE; } return(true); } finally { Kernel32.GlobalFree(data.hDevMode); Kernel32.GlobalFree(data.hDevNames); } }
internal HtmlElementCollection(HtmlShimManager shimManager, UnsafeNativeMethods.IHTMLElementCollection elements) { this.htmlElementCollection = elements; this.elementsArray = null; this.shimManager = shimManager; }
/// <include file='doc\Cursor.uex' path='docs/doc[@for="Cursor.Show"]/*' /> /// <devdoc> /// <para> /// Displays the cursor. For every call to Cursor.show() there must have been /// a previous call to Cursor.hide(). /// </para> /// </devdoc> public static void Show() { UnsafeNativeMethods.ShowCursor(true); }
/// <include file='doc\Cursor.uex' path='docs/doc[@for="Cursor.Hide"]/*' /> /// <devdoc> /// <para> /// Hides the cursor. For every call to Cursor.hide() there must be a /// balancing call to Cursor.show(). /// </para> /// </devdoc> public static void Hide() { UnsafeNativeMethods.ShowCursor(false); }
private unsafe long GetTypeInfoVersion(UnsafeNativeMethods.ITypeInfo pTypeInfo) { long num3; IntPtr zero = IntPtr.Zero; if (!System.Windows.Forms.NativeMethods.Succeeded(pTypeInfo.GetTypeAttr(ref zero))) { return 0L; } try { System.Runtime.InteropServices.ComTypes.TYPEATTR typeattr; try { typeattr = *((System.Runtime.InteropServices.ComTypes.TYPEATTR*) zero); } catch { return 0L; } long num2 = 0L; int* numPtr = (int*) &num2; byte* numPtr2 = (byte*) &typeattr; numPtr[0] = *((int*) (numPtr2 + CountMemberOffset)); numPtr++; numPtr[0] = *((int*) (numPtr2 + VersionOffset)); num3 = num2; } finally { pTypeInfo.ReleaseTypeAttr(zero); } return num3; }
void UnsafeNativeMethods.IDocHostShowUI.ShowHelp(ref UnsafeNativeMethods._RemotableHandle hwnd, string pszHelpFile, uint uCommand, uint dwData, UnsafeNativeMethods.tagPOINT ptMouse, object pDispatchObjectHit) { //TODO:自定义 }
private static void ProcessFunctions(UnsafeNativeMethods.ITypeInfo typeInfo, IDictionary propInfoList, int dispidToGet, int nameDispID, ref bool addAboutBox, StructCache structCache) { IntPtr zero = IntPtr.Zero; int typeAttr = typeInfo.GetTypeAttr(ref zero); if (!System.Windows.Forms.NativeMethods.Succeeded(typeAttr) || (zero == IntPtr.Zero)) { throw new ExternalException(System.Windows.Forms.SR.GetString("TYPEINFOPROCESSORGetTypeAttrFailed", new object[] { typeAttr }), typeAttr); } System.Windows.Forms.NativeMethods.tagTYPEATTR data = (System.Windows.Forms.NativeMethods.tagTYPEATTR) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagTYPEATTR)); UnsafeNativeMethods.PtrToStructure(zero, data); try { if (data != null) { System.Windows.Forms.NativeMethods.tagFUNCDESC gfuncdesc = (System.Windows.Forms.NativeMethods.tagFUNCDESC) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagFUNCDESC)); System.Windows.Forms.NativeMethods.tagELEMDESC structure = (System.Windows.Forms.NativeMethods.tagELEMDESC) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagELEMDESC)); for (int i = 0; i < data.cFuncs; i++) { IntPtr pFuncDesc = IntPtr.Zero; if (System.Windows.Forms.NativeMethods.Succeeded(typeInfo.GetFuncDesc(i, ref pFuncDesc)) && (pFuncDesc != IntPtr.Zero)) { UnsafeNativeMethods.PtrToStructure(pFuncDesc, gfuncdesc); try { if ((gfuncdesc.invkind == 1) || ((dispidToGet != -1) && (gfuncdesc.memid != dispidToGet))) { if (gfuncdesc.memid == -552) { addAboutBox = true; } } else { System.Windows.Forms.NativeMethods.tagTYPEDESC tdesc; bool flag = gfuncdesc.invkind == 2; if (flag) { if (gfuncdesc.cParams != 0) { continue; } tdesc = gfuncdesc.elemdescFunc.tdesc; } else { if ((gfuncdesc.lprgelemdescParam == IntPtr.Zero) || (gfuncdesc.cParams != 1)) { continue; } Marshal.PtrToStructure(gfuncdesc.lprgelemdescParam, structure); tdesc = structure.tdesc; } PropInfo info = ProcessDataCore(typeInfo, propInfoList, gfuncdesc.memid, nameDispID, tdesc, gfuncdesc.wFuncFlags, structCache); if ((info != null) && !flag) { info.ReadOnly = 2; } } } finally { typeInfo.ReleaseFuncDesc(pFuncDesc); } } } structCache.ReleaseStruct(gfuncdesc); structCache.ReleaseStruct(structure); } } finally { typeInfo.ReleaseTypeAttr(zero); structCache.ReleaseStruct(data); } }
void UnsafeNativeMethods.IDocHostShowUI.ShowMessage(ref UnsafeNativeMethods._RemotableHandle hwnd, string lpstrText, string lpstrCaption, uint dwType, string lpstrHelpFile, uint dwHelpContext, out int plResult) { plResult = 0; //TODO:自定义 }
private static void ProcessVariables(UnsafeNativeMethods.ITypeInfo typeInfo, IDictionary propInfoList, int dispidToGet, int nameDispID, StructCache structCache) { IntPtr zero = IntPtr.Zero; int typeAttr = typeInfo.GetTypeAttr(ref zero); if (!System.Windows.Forms.NativeMethods.Succeeded(typeAttr) || (zero == IntPtr.Zero)) { throw new ExternalException(System.Windows.Forms.SR.GetString("TYPEINFOPROCESSORGetTypeAttrFailed", new object[] { typeAttr }), typeAttr); } System.Windows.Forms.NativeMethods.tagTYPEATTR data = (System.Windows.Forms.NativeMethods.tagTYPEATTR) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagTYPEATTR)); UnsafeNativeMethods.PtrToStructure(zero, data); try { if (data != null) { System.Windows.Forms.NativeMethods.tagVARDESC gvardesc = (System.Windows.Forms.NativeMethods.tagVARDESC) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagVARDESC)); for (int i = 0; i < data.cVars; i++) { IntPtr pVarDesc = IntPtr.Zero; if (System.Windows.Forms.NativeMethods.Succeeded(typeInfo.GetVarDesc(i, ref pVarDesc)) && (pVarDesc != IntPtr.Zero)) { UnsafeNativeMethods.PtrToStructure(pVarDesc, gvardesc); try { if ((gvardesc.varkind != 2) && ((dispidToGet == -1) || (gvardesc.memid == dispidToGet))) { PropInfo info = ProcessDataCore(typeInfo, propInfoList, gvardesc.memid, nameDispID, gvardesc.elemdescVar.tdesc, gvardesc.wVarFlags, structCache); if (info.ReadOnly != 1) { info.ReadOnly = 2; } } } finally { if (pVarDesc != IntPtr.Zero) { typeInfo.ReleaseVarDesc(pVarDesc); } } } } structCache.ReleaseStruct(gvardesc); } } finally { typeInfo.ReleaseTypeAttr(zero); structCache.ReleaseStruct(data); } }
// for a given handle, finds the toplevel handle public static HandleRef GetRootHWnd(HandleRef hwnd) { IntPtr rootHwnd = UnsafeNativeMethods.GetAncestor(new HandleRef(hwnd, hwnd.Handle), NativeMethods.GA_ROOT); return(new HandleRef(hwnd.Wrapper, rootHwnd)); }
public DataStreamFromComStream(UnsafeNativeMethods.IStream comStream) { this.comStream = comStream; }
/// Translates a point from one control's coordinate system to the other /// same as: /// controlTo.PointToClient(controlFrom.PointToScreen(point)) /// but slightly more performant. public static Point TranslatePoint(Point point, Control fromControl, Control toControl) { NativeMethods.POINT pt = new NativeMethods.POINT(point.X, point.Y); UnsafeNativeMethods.MapWindowPoints(new HandleRef(fromControl, fromControl.Handle), new HandleRef(toControl, toControl.Handle), pt, 1); return(new Point(pt.x, pt.y)); }
int UnsafeNativeMethods.IOleContainer.EnumObjects(int grfFlags, out UnsafeNativeMethods.IEnumUnknown ppenum) { ppenum = null; if ((grfFlags & 1) != 0) { ArrayList list = new ArrayList(); this.ListAXControls(list, true); if (list.Count > 0) { object[] array = new object[list.Count]; list.CopyTo(array, 0); ppenum = new AxHost.EnumUnknown(array); return 0; } } ppenum = new AxHost.EnumUnknown(null); return 0; }
/// <summary> /// <para>Places data on the system <see cref='System.Windows.Forms.Clipboard'/> and uses copy to specify whether the data /// should remain on the <see cref='System.Windows.Forms.Clipboard'/> /// after the application exits.</para> /// </summary> public static void SetDataObject(object data, bool copy, int retryTimes, int retryDelay) { if (Application.OleRequired() != System.Threading.ApartmentState.STA) { throw new System.Threading.ThreadStateException(SR.ThreadMustBeSTA); } if (data == null) { throw new ArgumentNullException(nameof(data)); } if (retryTimes < 0) { throw new ArgumentOutOfRangeException(nameof(retryTimes), retryTimes, string.Format(SR.InvalidLowBoundArgumentEx, nameof(retryTimes), retryTimes, 0)); } if (retryDelay < 0) { throw new ArgumentOutOfRangeException(nameof(retryDelay), retryDelay, string.Format(SR.InvalidLowBoundArgumentEx, nameof(retryDelay), retryDelay, 0)); } DataObject dataObject = null; if (!(data is IComDataObject)) { dataObject = new DataObject(data); } // Compute the format of the "data" passed in iff setText == true; if (dataObject != null) { dataObject.RestrictedFormats = false; } int hr, retry = retryTimes; do { if (data is IComDataObject) { hr = UnsafeNativeMethods.OleSetClipboard((IComDataObject)data); } else { hr = UnsafeNativeMethods.OleSetClipboard(dataObject); } if (hr != 0) { if (retry == 0) { ThrowIfFailed(hr); } retry--; System.Threading.Thread.Sleep(retryDelay /*ms*/); } }while (hr != 0); if (copy) { retry = retryTimes; do { hr = UnsafeNativeMethods.OleFlushClipboard(); if (hr != 0) { if (retry == 0) { ThrowIfFailed(hr); } retry--; System.Threading.Thread.Sleep(retryDelay /*ms*/); } }while (hr != 0); } }
int UnsafeNativeMethods.IOleClientSite.GetContainer(out UnsafeNativeMethods.IOleContainer container) { container = this.Host.GetParentContainer(); return 0; }
/// <summary> /// Creates a window handle for this window. /// </summary> public virtual void CreateHandle(CreateParams cp) { lock (this) { CheckReleased(); WindowClass windowClass = WindowClass.Create(cp.ClassName, (NativeMethods.ClassStyle)cp.ClassStyle); lock (s_createWindowSyncObject) { // The CLR will sometimes pump messages while we're waiting on the lock. // If a message comes through (say a WM_ACTIVATE for the parent) which // causes the handle to be created, we can try to create the handle twice // for NativeWindow. Check the handle again to avoid this. if (Handle != IntPtr.Zero) { return; } windowClass._targetWindow = this; IntPtr createResult = IntPtr.Zero; int lastWin32Error = 0; // Parking window dpi awarness context need to match with dpi awarenss context of control being // parented to this parkign window. Otherwise, reparenting of control will fail. using (DpiHelper.EnterDpiAwarenessScope(DpiAwarenessContext)) { IntPtr modHandle = Kernel32.GetModuleHandleW(null); // Older versions of Windows AV rather than returning E_OUTOFMEMORY. // Catch this and then we re-throw an out of memory error. try { // CreateWindowEx throws if WindowText is greater than the max // length of a 16 bit int (32767). // If it exceeds the max, we should take the substring.... if (cp.Caption != null && cp.Caption.Length > short.MaxValue) { cp.Caption = cp.Caption.Substring(0, short.MaxValue); } createResult = UnsafeNativeMethods.CreateWindowEx( cp.ExStyle, windowClass._windowClassName, cp.Caption, cp.Style, cp.X, cp.Y, cp.Width, cp.Height, new HandleRef(cp, cp.Parent), NativeMethods.NullHandleRef, new HandleRef(null, modHandle), cp.Param); lastWin32Error = Marshal.GetLastWin32Error(); } catch (NullReferenceException e) { throw new OutOfMemoryException(SR.ErrorCreatingHandle, e); } } windowClass._targetWindow = null; Debug.WriteLineIf(CoreSwitches.PerfTrack.Enabled, "Handle created of type '" + cp.ClassName + "' with caption '" + cp.Caption + "' from NativeWindow of type '" + GetType().FullName + "'"); if (createResult == IntPtr.Zero) { throw new Win32Exception(lastWin32Error, SR.ErrorCreatingHandle); } _ownHandle = true; } } }
void UnsafeNativeMethods.IMsoComponent.OnActivationChange(UnsafeNativeMethods.IMsoComponent component, bool fSameComponent, int pcrinfo, bool fHostIsActivating, int pchostinfo, int dwReserved) { if (this._components != null) { foreach (UnsafeNativeMethods.IMsoComponent component2 in this._components.Values) { component2.OnActivationChange(component, fSameComponent, pcrinfo, fHostIsActivating, pchostinfo, dwReserved); } } }
bool UnsafeNativeMethods.IMsoComponentManager.FGetParentComponentManager(out UnsafeNativeMethods.IMsoComponentManager ppicm) { if (this._original == null) { ppicm = null; return false; } return this._original.FGetParentComponentManager(out ppicm); }
public static int GetNameDispId(UnsafeNativeMethods.IDispatch obj) { int num = -1; string[] rgszNames = null; ComNativeDescriptor instance = ComNativeDescriptor.Instance; bool succeeded = false; instance.GetPropertyValue(obj, "__id", ref succeeded); if (succeeded) { rgszNames = new string[] { "__id" }; } else { instance.GetPropertyValue(obj, -800, ref succeeded); if (succeeded) { num = -800; } else { instance.GetPropertyValue(obj, "Name", ref succeeded); if (succeeded) { rgszNames = new string[] { "Name" }; } } } if (rgszNames != null) { int[] rgDispId = new int[] { -1 }; Guid empty = Guid.Empty; if (System.Windows.Forms.NativeMethods.Succeeded(obj.GetIDsOfNames(ref empty, rgszNames, 1, SafeNativeMethods.GetThreadLCID(), rgDispId))) { num = rgDispId[0]; } } return num; }
/// <summary> /// Performs a hit-test at the specified insertion point /// and returns the closest item. /// </summary> /// public int NearestIndex(Point pt) { NativeMethods.LVINSERTMARK lvInsertMark = new NativeMethods.LVINSERTMARK(); UnsafeNativeMethods.SendMessage(new HandleRef(listView, listView.Handle), (int)LVM.INSERTMARKHITTEST, ref pt, lvInsertMark); return(lvInsertMark.iItem); }
bool UnsafeNativeMethods.IMsoComponentManager.FRegisterComponent(UnsafeNativeMethods.IMsoComponent component, System.Windows.Forms.NativeMethods.MSOCRINFOSTRUCT pcrinfo, out IntPtr dwComponentID) { if (component == null) { throw new ArgumentNullException("component"); } dwComponentID = IntPtr.Zero; if ((this._refCount == 0) && !this._original.FRegisterComponent(this, pcrinfo, out this._componentId)) { return false; } this._refCount++; if (this._components == null) { this._components = new Dictionary<int, UnsafeNativeMethods.IMsoComponent>(); } this._nextComponentId++; if (this._nextComponentId == 0x7fffffff) { this._nextComponentId = 1; } bool flag = false; while (this._components.ContainsKey(this._nextComponentId)) { this._nextComponentId++; if (this._nextComponentId == 0x7fffffff) { if (flag) { throw new InvalidOperationException(System.Windows.Forms.SR.GetString("ComponentManagerProxyOutOfMemory")); } flag = true; this._nextComponentId = 1; } } this._components.Add(this._nextComponentId, component); dwComponentID = (IntPtr) this._nextComponentId; return true; }
private static System.Type GetValueTypeFromTypeDesc(System.Windows.Forms.NativeMethods.tagTYPEDESC typeDesc, UnsafeNativeMethods.ITypeInfo typeInfo, object[] typeData, StructCache structCache) { IntPtr unionMember; int hr = 0; switch (((System.Windows.Forms.NativeMethods.tagVT) typeDesc.vt)) { case System.Windows.Forms.NativeMethods.tagVT.VT_DISPATCH: case System.Windows.Forms.NativeMethods.tagVT.VT_UNKNOWN: typeData[0] = GetGuidForTypeInfo(typeInfo, structCache, null); return VTToType((System.Windows.Forms.NativeMethods.tagVT) typeDesc.vt); case System.Windows.Forms.NativeMethods.tagVT.VT_PTR: { System.Windows.Forms.NativeMethods.tagTYPEDESC data = (System.Windows.Forms.NativeMethods.tagTYPEDESC) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagTYPEDESC)); try { try { UnsafeNativeMethods.PtrToStructure(typeDesc.unionMember, data); } catch { data = new System.Windows.Forms.NativeMethods.tagTYPEDESC { unionMember = (IntPtr) Marshal.ReadInt32(typeDesc.unionMember), vt = Marshal.ReadInt16(typeDesc.unionMember, 4) }; } if (data.vt == 12) { return VTToType((System.Windows.Forms.NativeMethods.tagVT) data.vt); } unionMember = data.unionMember; } finally { structCache.ReleaseStruct(data); } break; } case System.Windows.Forms.NativeMethods.tagVT.VT_USERDEFINED: unionMember = typeDesc.unionMember; break; default: return VTToType((System.Windows.Forms.NativeMethods.tagVT) typeDesc.vt); } UnsafeNativeMethods.ITypeInfo pTypeInfo = null; hr = typeInfo.GetRefTypeInfo(unionMember, ref pTypeInfo); if (!System.Windows.Forms.NativeMethods.Succeeded(hr)) { throw new ExternalException(System.Windows.Forms.SR.GetString("TYPEINFOPROCESSORGetRefTypeInfoFailed", new object[] { hr }), hr); } try { if (pTypeInfo != null) { IntPtr zero = IntPtr.Zero; hr = pTypeInfo.GetTypeAttr(ref zero); if (!System.Windows.Forms.NativeMethods.Succeeded(hr)) { throw new ExternalException(System.Windows.Forms.SR.GetString("TYPEINFOPROCESSORGetTypeAttrFailed", new object[] { hr }), hr); } System.Windows.Forms.NativeMethods.tagTYPEATTR gtypeattr = (System.Windows.Forms.NativeMethods.tagTYPEATTR) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagTYPEATTR)); UnsafeNativeMethods.PtrToStructure(zero, gtypeattr); try { Guid g = gtypeattr.guid; if (!Guid.Empty.Equals(g)) { typeData[0] = g; } switch (gtypeattr.typekind) { case 0: return ProcessTypeInfoEnum(pTypeInfo, structCache); case 3: case 5: return VTToType(System.Windows.Forms.NativeMethods.tagVT.VT_UNKNOWN); case 4: return VTToType(System.Windows.Forms.NativeMethods.tagVT.VT_DISPATCH); case 6: return GetValueTypeFromTypeDesc(gtypeattr.Get_tdescAlias(), pTypeInfo, typeData, structCache); } return null; } finally { pTypeInfo.ReleaseTypeAttr(zero); structCache.ReleaseStruct(gtypeattr); } } } finally { pTypeInfo = null; } return null; }
private static PropertyDescriptor[] InternalGetProperties(object obj, UnsafeNativeMethods.ITypeInfo typeInfo, int dispidToGet, ref int defaultIndex) { if (typeInfo == null) { return null; } Hashtable propInfoList = new Hashtable(); int nameDispId = GetNameDispId((UnsafeNativeMethods.IDispatch) obj); bool addAboutBox = false; StructCache structCache = new StructCache(); try { ProcessFunctions(typeInfo, propInfoList, dispidToGet, nameDispId, ref addAboutBox, structCache); } catch (ExternalException) { } try { ProcessVariables(typeInfo, propInfoList, dispidToGet, nameDispId, structCache); } catch (ExternalException) { } typeInfo = null; int count = propInfoList.Count; if (addAboutBox) { count++; } PropertyDescriptor[] descriptorArray = new PropertyDescriptor[count]; int hr = 0; object[] retval = new object[1]; ComNativeDescriptor instance = ComNativeDescriptor.Instance; foreach (PropInfo info in propInfoList.Values) { if (!info.NonBrowsable) { try { hr = instance.GetPropertyValue(obj, info.DispId, retval); } catch (ExternalException exception) { hr = exception.ErrorCode; } if (!System.Windows.Forms.NativeMethods.Succeeded(hr)) { info.Attributes.Add(new BrowsableAttribute(false)); info.NonBrowsable = true; } } else { hr = 0; } Attribute[] array = new Attribute[info.Attributes.Count]; info.Attributes.CopyTo(array, 0); descriptorArray[info.Index] = new Com2PropertyDescriptor(info.DispId, info.Name, array, info.ReadOnly != 2, info.ValueType, info.TypeData, !System.Windows.Forms.NativeMethods.Succeeded(hr)); if (info.IsDefault) { int index = info.Index; } } if (addAboutBox) { descriptorArray[descriptorArray.Length - 1] = new Com2AboutBoxPropertyDescriptor(); } return descriptorArray; }
/// <include file='doc\PageSetupDialog.uex' path='docs/doc[@for="PageSetupDialog.RunDialog"]/*' /> /// <devdoc> /// </devdoc> /// <internalonly/> protected override bool RunDialog(IntPtr hwndOwner) { IntSecurity.SafePrinting.Demand(); NativeMethods.WndProc hookProcPtr = new NativeMethods.WndProc(this.HookProc); if (pageSettings == null) { throw new ArgumentException(SR.PSDcantShowWithoutPage); } NativeMethods.PAGESETUPDLG data = new NativeMethods.PAGESETUPDLG(); data.lStructSize = Marshal.SizeOf(data); data.Flags = GetFlags(); data.hwndOwner = hwndOwner; data.lpfnPageSetupHook = hookProcPtr; PrinterUnit toUnit = PrinterUnit.ThousandthsOfAnInch; // Below was a breaking change from RTM and EVERETT even though this was a correct FIX. // EnableMetric is a new Whidbey property which we allow the users to choose between the AutoConversion or not. if (EnableMetric) { //take the Units of Measurement while determining the PrinterUnits... // StringBuilder sb = new StringBuilder(2); int result = UnsafeNativeMethods.GetLocaleInfo(NativeMethods.LOCALE_USER_DEFAULT, NativeMethods.LOCALE_IMEASURE, sb, sb.Capacity); if (result > 0 && Int32.Parse(sb.ToString(), CultureInfo.InvariantCulture) == 0) { toUnit = PrinterUnit.HundredthsOfAMillimeter; } } if (MinMargins != null) { Margins margins = PrinterUnitConvert.Convert(MinMargins, PrinterUnit.Display, toUnit); data.minMarginLeft = margins.Left; data.minMarginTop = margins.Top; data.minMarginRight = margins.Right; data.minMarginBottom = margins.Bottom; } if (pageSettings.Margins != null) { Margins margins = PrinterUnitConvert.Convert(pageSettings.Margins, PrinterUnit.Display, toUnit); data.marginLeft = margins.Left; data.marginTop = margins.Top; data.marginRight = margins.Right; data.marginBottom = margins.Bottom; } // Ensure that the margins are >= minMargins. // This is a requirement of the PAGESETUPDLG structure. // data.marginLeft = Math.Max(data.marginLeft, data.minMarginLeft); data.marginTop = Math.Max(data.marginTop, data.minMarginTop); data.marginRight = Math.Max(data.marginRight, data.minMarginRight); data.marginBottom = Math.Max(data.marginBottom, data.minMarginBottom); PrinterSettings printer = (printerSettings == null) ? pageSettings.PrinterSettings : printerSettings; // GetHDevmode demands AllPrintingAndUnmanagedCode Permission : Since we are calling that function we should Assert the permision, IntSecurity.AllPrintingAndUnmanagedCode.Assert(); try { data.hDevMode = printer.GetHdevmode(pageSettings); data.hDevNames = printer.GetHdevnames(); } finally { CodeAccessPermission.RevertAssert(); } try { bool status = UnsafeNativeMethods.PageSetupDlg(data); if (!status) { // Debug.WriteLine(Windows.CommonDialogErrorToString(Windows.CommDlgExtendedError())); return(false); } UpdateSettings(data, pageSettings, printerSettings); // yes, printerSettings, not printer return(true); } finally { UnsafeNativeMethods.GlobalFree(new HandleRef(data, data.hDevMode)); UnsafeNativeMethods.GlobalFree(new HandleRef(data, data.hDevNames)); } }