1 //----------------------------------------------------------------------
3 // Copyright (c) Microsoft Corporation.
4 // All rights reserved.
6 // This code is licensed under the MIT License.
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files(the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions :
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 //------------------------------------------------------------------------------
30 using System.Runtime.InteropServices;
32 namespace Microsoft.IdentityModel.Clients.ActiveDirectory.Internal
34 internal class NativeWrapper
36 [StructLayout(LayoutKind.Sequential)]
46 public POINT(int x, int y)
53 [StructLayout(LayoutKind.Sequential)]
56 [MarshalAs(UnmanagedType.U4)]
58 [MarshalAs(UnmanagedType.U4)]
62 [ComImport, ComVisible(true), Guid("B722BCCB-4E68-101B-A2BC-00AA00404770"),
63 InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
64 public interface IOleCommandTarget
66 [return: MarshalAs(UnmanagedType.I4)]
68 int QueryStatus(ref Guid pguidCmdGroup, int cCmds, [In, Out] OLECMD prgCmds, [In, Out] IntPtr pCmdText);
70 [return: MarshalAs(UnmanagedType.I4)]
72 int Exec(IntPtr guid, int nCmdID, int nCmdexecopt,
73 [In, MarshalAs(UnmanagedType.LPArray)] object[] pvaIn, IntPtr pvaOut);
76 [StructLayout(LayoutKind.Sequential), ComVisible(true)]
77 public class DOCHOSTUIINFO
79 [MarshalAs(UnmanagedType.U4)]
80 public int cbSize = Marshal.SizeOf(typeof(DOCHOSTUIINFO));
81 [MarshalAs(UnmanagedType.I4)]
83 [MarshalAs(UnmanagedType.I4)]
84 public int dwDoubleClick;
85 [MarshalAs(UnmanagedType.I4)]
86 public int dwReserved1;
87 [MarshalAs(UnmanagedType.I4)]
88 public int dwReserved2;
91 [Serializable, StructLayout(LayoutKind.Sequential)]
103 [StructLayout(LayoutKind.Sequential)]
111 public override string ToString()
114 string.Concat(new object[] { "Left = ", this.left, " Top ", this.top, " Right = ", this.right, " Bottom = ", this.bottom });
121 public COMRECT(Rectangle r)
125 this.right = r.Right;
126 this.bottom = r.Bottom;
129 public COMRECT(int left, int top, int right, int bottom)
134 this.bottom = bottom;
137 public static COMRECT FromXYWH(int x, int y, int width, int height)
139 return new COMRECT(x, y, x + width, y + height);
143 [ComImport, Guid("00000115-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
144 public interface IOleInPlaceUIWindow
149 int ContextSensitiveHelp(int fEnterMode);
152 int GetBorder([Out] COMRECT lprectBorder);
155 int RequestBorderSpace([In] COMRECT pborderwidths);
158 int SetBorderSpace([In] COMRECT pborderwidths);
160 void SetActiveObject([In, MarshalAs(UnmanagedType.Interface)] IOleInPlaceActiveObject pActiveObject,
161 [In, MarshalAs(UnmanagedType.LPWStr)] string pszObjName);
164 [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00000117-0000-0000-C000-000000000046")]
165 public interface IOleInPlaceActiveObject
168 int GetWindow(out IntPtr hwnd);
170 void ContextSensitiveHelp(int fEnterMode);
173 int TranslateAccelerator([In] ref MSG lpmsg);
175 void OnFrameWindowActivate(bool fActivate);
176 void OnDocWindowActivate(int fActivate);
177 void ResizeBorder([In] COMRECT prcBorder, [In] IOleInPlaceUIWindow pUIWindow, bool fFrameWindow);
178 void EnableModeless(int fEnable);
181 [StructLayout(LayoutKind.Sequential)]
182 public sealed class tagOleMenuGroupWidths
184 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
185 public int[] widths = new int[6];
188 [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00000116-0000-0000-C000-000000000046")]
189 public interface IOleInPlaceFrame
194 int ContextSensitiveHelp(int fEnterMode);
197 int GetBorder([Out] COMRECT lprectBorder);
200 int RequestBorderSpace([In] COMRECT pborderwidths);
203 int SetBorderSpace([In] COMRECT pborderwidths);
206 int SetActiveObject([In, MarshalAs(UnmanagedType.Interface)] IOleInPlaceActiveObject pActiveObject,
207 [In, MarshalAs(UnmanagedType.LPWStr)] string pszObjName);
210 int InsertMenus([In] IntPtr hmenuShared, [In, Out] tagOleMenuGroupWidths lpMenuWidths);
213 int SetMenu([In] IntPtr hmenuShared, [In] IntPtr holemenu, [In] IntPtr hwndActiveObject);
216 int RemoveMenus([In] IntPtr hmenuShared);
219 int SetStatusText([In, MarshalAs(UnmanagedType.LPWStr)] string pszStatusText);
222 int EnableModeless(bool fEnable);
225 int TranslateAccelerator([In] ref MSG lpmsg, [In, MarshalAs(UnmanagedType.U2)] short wID);
228 [ComImport, Guid("00000122-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
229 public interface IOleDropTarget
232 int OleDragEnter([In, MarshalAs(UnmanagedType.Interface)] object pDataObj,
233 [In, MarshalAs(UnmanagedType.U4)] int grfKeyState, [In] POINT pt,
234 [In, Out] ref int pdwEffect);
237 int OleDragOver([In, MarshalAs(UnmanagedType.U4)] int grfKeyState, [In] POINT pt,
238 [In, Out] ref int pdwEffect);
244 int OleDrop([In, MarshalAs(UnmanagedType.Interface)] object pDataObj,
245 [In, MarshalAs(UnmanagedType.U4)] int grfKeyState, [In] POINT pt, [In, Out] ref int pdwEffect);
248 [ComImport, ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
249 Guid("BD3F23C0-D43E-11CF-893B-00AA00BDCE1A")]
250 public interface IDocHostUIHandler
252 [return: MarshalAs(UnmanagedType.I4)]
254 int ShowContextMenu([In, MarshalAs(UnmanagedType.U4)] int dwID, [In] POINT pt,
255 [In, MarshalAs(UnmanagedType.Interface)] object pcmdtReserved,
256 [In, MarshalAs(UnmanagedType.Interface)] object pdispReserved);
258 [return: MarshalAs(UnmanagedType.I4)]
260 int GetHostInfo([In, Out] DOCHOSTUIINFO info);
262 [return: MarshalAs(UnmanagedType.I4)]
264 int ShowUI([In, MarshalAs(UnmanagedType.I4)] int dwID, [In] IOleInPlaceActiveObject activeObject,
265 [In] IOleCommandTarget commandTarget, [In] IOleInPlaceFrame frame, [In] IOleInPlaceUIWindow doc);
267 [return: MarshalAs(UnmanagedType.I4)]
271 [return: MarshalAs(UnmanagedType.I4)]
275 [return: MarshalAs(UnmanagedType.I4)]
277 int EnableModeless([In, MarshalAs(UnmanagedType.Bool)] bool fEnable);
279 [return: MarshalAs(UnmanagedType.I4)]
281 int OnDocWindowActivate([In, MarshalAs(UnmanagedType.Bool)] bool fActivate);
283 [return: MarshalAs(UnmanagedType.I4)]
285 int OnFrameWindowActivate([In, MarshalAs(UnmanagedType.Bool)] bool fActivate);
287 [return: MarshalAs(UnmanagedType.I4)]
289 int ResizeBorder([In] COMRECT rect, [In] IOleInPlaceUIWindow doc, bool fFrameWindow);
291 [return: MarshalAs(UnmanagedType.I4)]
293 int TranslateAccelerator([In] ref MSG msg, [In] ref Guid group, [In, MarshalAs(UnmanagedType.I4)] int nCmdID);
295 [return: MarshalAs(UnmanagedType.I4)]
297 int GetOptionKeyPath([Out, MarshalAs(UnmanagedType.LPArray)] string[] pbstrKey,
298 [In, MarshalAs(UnmanagedType.U4)] int dw);
300 [return: MarshalAs(UnmanagedType.I4)]
302 int GetDropTarget([In, MarshalAs(UnmanagedType.Interface)] IOleDropTarget pDropTarget,
303 [MarshalAs(UnmanagedType.Interface)] out IOleDropTarget ppDropTarget);
305 [return: MarshalAs(UnmanagedType.I4)]
307 int GetExternal([MarshalAs(UnmanagedType.Interface)] out object ppDispatch);
309 [return: MarshalAs(UnmanagedType.I4)]
311 int TranslateUrl([In, MarshalAs(UnmanagedType.U4)] int dwTranslate,
312 [In, MarshalAs(UnmanagedType.LPWStr)] string strURLIn,
313 [MarshalAs(UnmanagedType.LPWStr)] out string pstrURLOut);
315 [return: MarshalAs(UnmanagedType.I4)]
317 // Please, don't use System.Windows.Forms.IDataObject it is wrong one.
318 int FilterDataObject(System.Runtime.InteropServices.ComTypes.IDataObject pDO, out System.Runtime.InteropServices.ComTypes.IDataObject ppDORet);
322 [Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E")]
323 [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
324 public interface IWebBrowser2
327 object Document { [return: MarshalAs(UnmanagedType.IDispatch)] [DispId(0xcb)] get; }
330 bool Silent { [param: MarshalAs(UnmanagedType.Bool)] [DispId(0x227)]set; }
333 [ComImport, Guid("34A715A0-6587-11D0-924A-0020AFC7AC4D"), TypeLibType(TypeLibTypeFlags.FHidden), InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
334 public interface DWebBrowserEvents2
337 void StatusTextChange([In] string text);
339 void ProgressChange([In] int progress, [In] int progressMax);
341 void CommandStateChange([In] long command, [In] bool enable);
343 void DownloadBegin();
345 void DownloadComplete();
347 void TitleChange([In] string text);
349 void PropertyChange([In] string szProperty);
351 void BeforeNavigate2([In, MarshalAs(UnmanagedType.IDispatch)] object pDisp, [In] ref object URL, [In] ref object flags, [In] ref object targetFrameName, [In] ref object postData, [In] ref object headers, [In, Out] ref bool cancel);
353 void NewWindow2([In, Out, MarshalAs(UnmanagedType.IDispatch)] ref object pDisp, [In, Out] ref bool cancel);
355 void NavigateComplete2([In, MarshalAs(UnmanagedType.IDispatch)] object pDisp, [In] ref object URL);
357 void DocumentComplete([In, MarshalAs(UnmanagedType.IDispatch)] object pDisp, [In] ref object URL);
361 void OnVisible([In] bool visible);
363 void OnToolBar([In] bool toolBar);
365 void OnMenuBar([In] bool menuBar);
367 void OnStatusBar([In] bool statusBar);
369 void OnFullScreen([In] bool fullScreen);
371 void OnTheaterMode([In] bool theaterMode);
373 void WindowSetResizable([In] bool resizable);
375 void WindowSetLeft([In] int left);
377 void WindowSetTop([In] int top);
379 void WindowSetWidth([In] int width);
381 void WindowSetHeight([In] int height);
383 void WindowClosing([In] bool isChildWindow, [In, Out] ref bool cancel);
385 void ClientToHostWindow([In, Out] ref long cx, [In, Out] ref long cy);
387 void SetSecureLockIcon([In] int secureLockIcon);
389 void FileDownload([In, Out] ref bool cancel);
391 void NavigateError([In, MarshalAs(UnmanagedType.IDispatch)] object pDisp, [In] ref object URL, [In] ref object frame, [In] ref object statusCode, [In, Out] ref bool cancel);
393 void PrintTemplateInstantiation([In, MarshalAs(UnmanagedType.IDispatch)] object pDisp);
395 void PrintTemplateTeardown([In, MarshalAs(UnmanagedType.IDispatch)] object pDisp);
397 void UpdatePageStatus([In, MarshalAs(UnmanagedType.IDispatch)] object pDisp, [In] ref object nPage, [In] ref object fDone);
399 void PrivacyImpactedStateChange([In] bool bImpacted);
402 internal static class NativeMethods
404 [DllImport("User32.dll", CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]
405 internal static extern IntPtr GetDC(IntPtr hWnd);
407 [DllImport("User32.dll", CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]
408 internal static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
410 [DllImport("Gdi32.dll", CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]
411 internal static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
413 [DllImport("User32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
414 internal static extern bool IsProcessDPIAware();