<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>.NET Compact Framework Team : Author: Katie Blanch</title><link>http://blogs.msdn.com/netcfteam/archive/tags/Author_3A00_+Katie+Blanch/default.aspx</link><description>Tags: Author: Katie Blanch</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Interop: Extending GUI Functionality</title><link>http://blogs.msdn.com/netcfteam/archive/2005/07/24/442616.aspx</link><pubDate>Sun, 24 Jul 2005 11:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:442616</guid><dc:creator>NetCFTeam</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/netcfteam/comments/442616.aspx</comments><wfw:commentRss>http://blogs.msdn.com/netcfteam/commentrss.aspx?PostID=442616</wfw:commentRss><description>&lt;P&gt;&lt;FONT color=#000080 size=5&gt;&lt;STRONG&gt;Interop: Extending GUI Functionality&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This post will describe some ways you can use the new interop features present in version 2 of the .Net Compact Framework to extend the framework's GUI functionality present in the System.Windows.Forms namespace.&amp;nbsp; An overview of how GUI works under the hood is also provided to give developers an understanding of the limitations and assumptions that the framework will make when using interop to override or extend the framework.&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#808080 size=5&gt;&lt;STRONG&gt;Under the Hood&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;The functionality exposed through the System.Windows.Forms namespace is implemented in two parts.&amp;nbsp; There is a native layer, present inside netcfagl2_0.dll, which handles most of the logic required for GUI features and is responsible for interacting with the underlying Windows CE OS.&amp;nbsp; The second part is the managed layer, present inside System.Windows.Forms.dll, which for the most part is actually a relatively thin wrapper that contains very little logic and mostly just exposes functionality to the managed world.&amp;nbsp; &lt;BR&gt;There are a couple of implementation details that you should keep in mind when using interop to extend current functionality.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The runtime will attempt to maintain the managed state of GUI controls and components.&amp;nbsp; For example, if you PInvoke to SHFullScreen to hide the task bar, the runtime may override this behavior at a later time with its understanding of the managed state.&lt;/LI&gt;
&lt;LI&gt;Forms will have logic under the scenes to support features like tabbing, autoscroll, docking and anchoring.&amp;nbsp; The logic for these features often involves examining and manipulating controls parented to the form, and can occur in response to messages received by the form as well as in response to GUI API calls.&lt;/LI&gt;
&lt;LI&gt;All managed controls use the GWL_USERDATA space, and the runtime expects the data stored here to remain valid.&amp;nbsp; This area is considered to be reserved for runtime use only and should not be examined or relied upon.&lt;/LI&gt;
&lt;LI&gt;Managed forms and controls may be recreated as necessary when their attributes are modified.&amp;nbsp; Any modifications that were made to the native control via interop are not guaranteed to be re-applied to the newly created control.&amp;nbsp; Also, the value returned from Control.Handle, associated with the native HWND, will change.&lt;/LI&gt;
&lt;LI&gt;Managed controls are often implemented by wrapping functionality exposed in a similar native control present in the OS.&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;In some cases, a single managed control may be associated with two native controls (such as the NumericUpDown control).&amp;nbsp; The Control.Handle API will return the handle associated with the major native control of the pair (in the case of NumericUpDown, it will be the Edit control).&amp;nbsp; You can use the remote spy tool to further examine the hierarchy of managed controls.&lt;/LI&gt;
&lt;LI&gt;For performance reasons, not all events are sent up to the managed code layer.&amp;nbsp; &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT color=#808080 size=5&gt;&lt;STRONG&gt;Using Interop Features&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P dir=ltr style="MARGIN-RIGHT: 0px"&gt;A number of interop features have been added to the .Net Compact Framework, making it possible for developers to dramatically extend the framework without writing native code.&lt;/P&gt;
&lt;UL dir=ltr&gt;
&lt;LI&gt;
&lt;DIV style="MARGIN-RIGHT: 0px"&gt;Delegate callbacks, which allow you to override the wndproc of native controls and get notified when messages are received by the native control.&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV style="MARGIN-RIGHT: 0px"&gt;Marshaling support for more types, including support for more types of fields in structures.&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV style="MARGIN-RIGHT: 0px"&gt;The InteropServices.Marshal class has been extended, allowing you to access marshaling functionality from managed code and convert between IntPtrs and objects.&amp;nbsp; This is especially useful when the interop functions, such as wndprocs, contain parameters that can be either an int or a pointer to a structure based on what context they are called in.&amp;nbsp; You may find Marshal.PtrToStructure and Marshal.StructureToPtr useful to convert between an IntPtr, representing a native pointer to a structure, and a managed instance of the structure.&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV style="MARGIN-RIGHT: 0px"&gt;COM Interop support, which provides the pluming necessary to host ActiveX controls.&amp;nbsp; An ActiveX container can now be implemented entirely in managed code.&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;When using interop features to interact with managed controls and components, follow these guidelines:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Whenever possible, you should use managed APIs to modify the state of a control or the system, and rely on interop only as a last resort.&lt;/LI&gt;
&lt;LI&gt;When parenting native controls inside a managed form, provide a level of indirection between the form and the native control by wrapping the native control inside a managed Control or UserControl.&amp;nbsp; This will protect the native control from being frequently examined and manipulated by the runtime; since the runtime will instead reference the parent managed Control.&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;Be aware that sending a message to a managed control may have side-effects (or may start to have side effects in future versions).&amp;nbsp; The only way to completely prevent runtime logic from executing is to send a message directly to a native control that has been created using interop.&amp;nbsp; In general, sending messages directly to a managed form must be done with care as there may be assumptions about the existence of a managed control or component that would typically send that message.&lt;/LI&gt;
&lt;LI&gt;When spying on messages sent to a managed control by overriding the wndproc, be sure to call the original wndproc (which will often be the runtime).&amp;nbsp; If the original wndproc is not called, there may be undesirable side-effects causing core features such as tabbing, autoscroll, and layout (among other things) to break.&lt;/LI&gt;
&lt;LI&gt;For compatibility against future versions of the framework, it can be safer to wrap a native control from scratch, then to modify the state of a managed control.&amp;nbsp; When using interop to extend the framework, think about how your code will function if the feature you are implementing is eventually added to the framework.&lt;/LI&gt;
&lt;LI&gt;Do not rely on implementation details, as they may change in future versions.&amp;nbsp; Do not attempt to parse or change any runtime owned data structures.&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;Do not rely on the order, timing or frequency of events.&amp;nbsp; &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT color=#808080 size=5&gt;&lt;STRONG&gt;Resources&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;The following blog posts describe how to extend the functionality of currently exposed controls.&amp;nbsp; This will show how to use interop to add 'missing' events to managed controls.&lt;BR&gt;Part 1: &lt;a href="http://blogs.msdn.com/netcfteam/archive/2005/05/20/420551.aspx"&gt;http://blogs.msdn.com/netcfteam/archive/2005/05/20/420551.aspx&lt;/A&gt;&lt;BR&gt;Part 2: &lt;a href="http://blogs.msdn.com/netcfteam/archive/2005/05/23/421143.aspx"&gt;http://blogs.msdn.com/netcfteam/archive/2005/05/23/421143.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The following information may be useful when attempting to diagnose and solve issues involving interop.&lt;BR&gt;&lt;a href="http://blogs.msdn.com/netcfteam/archive/2005/07/24/442612.aspx"&gt;http://blogs.msdn.com/netcfteam/archive/2005/07/24/442612.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;All applications should be tested with Interop Logging turned on, even if there are no known issues.&amp;nbsp; This will produce a log file that should then be searched for 'ERROR' and 'WARNING'.&amp;nbsp; The log file will contain more information about the cause of managed exceptions, subtle errors that do not manifest themselves as managed exceptions, as well as assist in debugging interop issues involving native code for which the source is unavailable.&lt;BR&gt;&lt;a href="http://blogs.msdn.com/netcfteam/archive/2005/07/24/442609.aspx"&gt;http://blogs.msdn.com/netcfteam/archive/2005/07/24/442609.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;There are interop and GUI related guidelines and tips that can drastically improve your application's performance:&lt;BR&gt;&lt;a href="http://blogs.msdn.com/netcfteam/archive/2005/05/04/414820.aspx"&gt;http://blogs.msdn.com/netcfteam/archive/2005/05/04/414820.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#808080 size=5&gt;&lt;STRONG&gt;Sample Code - Wrapping Native Controls&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This sample presents a generic WindowHost class that you can use to host any native control on a managed form.&amp;nbsp; Sample code is shown using this class to host the RichInk control.&lt;/P&gt;
&lt;P&gt;using System;&lt;BR&gt;using System.Windows.Forms;&lt;BR&gt;using System.Runtime.InteropServices;&lt;BR&gt;using System.Diagnostics;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;namespace GuiInterop&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;/// This is a generic host that will allow you to create a native &lt;BR&gt;&amp;nbsp;/// control and parent it to your managed form.&amp;nbsp; You will also be &lt;BR&gt;&amp;nbsp;/// able to spy and respond to messsages the native control &lt;BR&gt;&amp;nbsp;/// recieves, and send messages to the native control.&lt;BR&gt;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;public class WindowHost : Control&lt;BR&gt;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;private IntPtr m_hwnd;&amp;nbsp;// the window handle of the native &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// control&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;private IntPtr m_wndprocReal;&amp;nbsp;// the original wndproc of &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// the native control before &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// it is subclassed&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;private WindowsAPIs.WindowProcCallback m_delegate;&amp;nbsp;// the &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// delegate used to get &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// message callbacks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// This event will fire before the message is sent down to &lt;BR&gt;&amp;nbsp;&amp;nbsp;///&amp;nbsp;the native control for processing, allowing you to &lt;BR&gt;&amp;nbsp;&amp;nbsp;///&amp;nbsp;preview and respond to the message. &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;public event MessageEventHandler MessageReceived;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// The HWND associated with the native control being hosted.&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;public IntPtr NativeHandle&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return m_hwnd;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// Create a native control and embeds it inside the host.&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;param name="strClassName"&amp;gt;The class name of the native &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// control to be created. This can be either a system class &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// or a custom native control that has been registered on &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// the system through RegisterClassEx. &amp;lt;/param&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;param name="wsEx"&amp;gt;The extended window style of the native &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// control to be created. &amp;lt;/param&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;param name="ws"&amp;gt;The style of the native control to be &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// created. &amp;lt;/param&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;public WindowHost(string strClassName, uint wsEx, uint ws)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;#if DESKTOP&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Under the desktop framework, ensure this control has been fully&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; * created and has a valid hwnd.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.CreateHandle();&lt;BR&gt;#endif&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Debug.Assert(this.Handle != IntPtr.Zero, "Control should have a handle created by now");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Create the native control and parent it to this control. */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_hwnd = WindowsAPIs.CreateWindowExW(wsEx, strClassName, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;null, ws | WindowsAPIs.WS_CHILD | WindowsAPIs.WS_VISIBLE, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0, 0, 0, 0, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.Handle, 0, 0, 0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (m_hwnd == IntPtr.Zero) {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Class not registered */&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Debug.Assert(false, "Class not registered");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;throw new OutOfMemoryException();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Latch onto windows messages by subclassing the native &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; * control &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_delegate = new WindowsAPIs.WindowProcCallback(this.WnProc);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_wndprocReal = WindowsAPIs.SetWindowLong(m_hwnd, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.GWL_WNDPROC, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Marshal.GetFunctionPointerForDelegate(m_delegate));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// Embeds a native control it inside the host.&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;public WindowHost(IntPtr hwndNativeControl)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;#if DESKTOP&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Under the desktop framework, ensure this control has been fully&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; * created and has a valid hwnd.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.CreateHandle();&lt;BR&gt;#endif&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Debug.Assert(hwndNativeControl != IntPtr.Zero, "Control should have a handle created by now");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Debug.Assert(this.Handle != IntPtr.Zero, "Control should have a handle created by now");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_hwnd = hwndNativeControl;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Latch onto windows messages by subclassing the native &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; * control &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_delegate = new WindowsAPIs.WindowProcCallback(this.WnProc);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_wndprocReal = WindowsAPIs.SetWindowLong(m_hwnd, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.GWL_WNDPROC, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Marshal.GetFunctionPointerForDelegate(m_delegate));&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// WnProc called used to monitor all messages the native control &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// receives.&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;private int WnProc(IntPtr hwnd, uint msg, uint wParam, uint lParam)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;int ret;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;MessageEventArgs e;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;e = new MessageEventArgs(hwnd, msg, wParam, lParam);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.OnMessageReceived(e);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if ((msg == WindowsAPIs.WM_DESTROY) &amp;amp;&amp;amp; (!e.Handled)) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* De-subclass the child hwnd */&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.SetWindowLong(m_hwnd, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.GWL_WNDPROC, m_wndprocReal);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (e.Handled) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Give the original wnd proc a chance to process the &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * message &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ret = WindowsAPIs.CallWindowProc(m_wndprocReal, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;hwnd, msg, wParam, lParam);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ret = e.ReturnValue;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return ret;&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// Used to ensure the native control remains the same size &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// as the host control.&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;protected override void OnResize(EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.SetWindowPos(m_hwnd, 0, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0, 0, this.ClientSize.Width, this.ClientSize.Height, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.SWP_NOZORDER);&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// Applies the window text of the host control to the &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// native control as well.&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;protected override void OnTextChanged(EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.SetWindowText(m_hwnd, this.Text);&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// Any time focus is given to the host control, it is passed &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// down to the hosted native control.&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;protected override void OnGotFocus(EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.SetFocus(m_hwnd);&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// Called each time a message is received by the native &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// control, and fires associated event.&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;protected void OnMessageReceived(MessageEventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (this.MessageReceived != null)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.MessageReceived(this, e);&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;/// Delegate used to spy and respond to messages received by &lt;BR&gt;&amp;nbsp;/// the hosted native control.&lt;BR&gt;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;public delegate void MessageEventHandler(object sender, MessageEventArgs e);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;/// Used to encapsulate the data present in a wndproc message.&lt;BR&gt;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;public class MessageEventArgs : EventArgs&lt;BR&gt;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;private IntPtr m_hwnd;&lt;BR&gt;&amp;nbsp;&amp;nbsp;private uint m_msg;&lt;BR&gt;&amp;nbsp;&amp;nbsp;private uint m_wParam;&lt;BR&gt;&amp;nbsp;&amp;nbsp;private uint m_lParam;&lt;BR&gt;&amp;nbsp;&amp;nbsp;private bool m_fHandled;&lt;BR&gt;&amp;nbsp;&amp;nbsp;private int m_ret;&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;public MessageEventArgs(IntPtr hwnd, uint msg, uint wParam, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;uint lParam)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_fHandled = true;&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// The window handle associated with the message.&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;public IntPtr Hwnd&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;get &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return m_hwnd;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// The ID used to identify the message (WM_*).&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;public uint Msg&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return m_msg;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// The wParam associated with the message, whose value &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// depends on the message.&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;public uint wParam&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return m_wParam;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// The lParam associated with the message, whose value &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// depends on the message.&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;public uint lParam&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return m_lParam;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// Determines if the message is to be sent to the native &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// control's wndproc for further processing.&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;public bool Handled&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return m_fHandled;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;set&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_fHandled = value;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;/// Determines the return value to be returned from the wndproc &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// to the sender of the message. &lt;BR&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;public int ReturnValue&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return m_ret;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;set &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_ret = value;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;using System;&lt;BR&gt;using System.Windows.Forms;&lt;BR&gt;using System.Runtime.InteropServices;&lt;BR&gt;using GuiInterop;&lt;/P&gt;
&lt;P&gt;namespace HostDemo&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;public class SampleForm : Form&lt;BR&gt;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;private WindowHost m_ctlRichInk;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;public SampleForm()&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;InitInkX();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_ctlRichInk = new WindowHost("InkX", 0, 0);&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_ctlRichInk.Height = 150;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_ctlRichInk.Dock = DockStyle.Fill;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_ctlRichInk.Parent = this;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.SendMessage(m_ctlRichInk.NativeHandle, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.EM_SETVIEW, WindowsAPIs.VT_DRAWINGVIEW, 0);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.SendMessage(m_ctlRichInk.NativeHandle, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.EM_SETPENMODE, WindowsAPIs.MODE_PEN, 0);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.SendMessage(m_ctlRichInk.NativeHandle, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.EM_SETINKLAYER, WindowsAPIs.VL_DRAWINGINK, 0);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.SendMessage(m_ctlRichInk.NativeHandle, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WindowsAPIs.EM_SETPAGESTYLE, WindowsAPIs.PS_RULEDLINES, 0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.Text = "Hosting Sample";&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.MinimizeBox = false;&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;#if DESKTOP&lt;BR&gt;&amp;nbsp;&amp;nbsp;[STAThread]&lt;BR&gt;#endif&lt;BR&gt;&amp;nbsp;&amp;nbsp;static void Main()&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Application.Run(new SampleForm());&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;[DllImport ("inkx.dll")]&lt;BR&gt;&amp;nbsp;&amp;nbsp;public static extern void InitInkX();&lt;BR&gt;&amp;nbsp;}&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;using System;&lt;BR&gt;using System.Runtime.InteropServices;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;namespace GuiInterop&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;/// Contains managed wrappers of windows APIs necessary for pinvokes&lt;BR&gt;&amp;nbsp;/// and delegate callbacks.&lt;BR&gt;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;public sealed class WindowsAPIs&lt;BR&gt;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;public delegate int WindowProcCallback(IntPtr hwnd, uint msg, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;uint wParam, uint lParam);&lt;/P&gt;
&lt;P&gt;#if DESKTOP&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("user32.dll")]&lt;BR&gt;#else&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("coredll.dll")]&lt;BR&gt;#endif&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;public extern static int DefWindowProc(IntPtr hwnd, uint msg, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;uint wParam, uint lParam);&lt;/P&gt;
&lt;P&gt;#if DESKTOP&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("user32.dll")]&lt;BR&gt;#else&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("coredll.dll")]&lt;BR&gt;#endif&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;public extern static int CallWindowProc(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;IntPtr lpPrevWndFunc, IntPtr hwnd, uint msg, uint wParam, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;uint lParam);&lt;BR&gt;&amp;nbsp;&lt;BR&gt;#if DESKTOP&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("user32.dll")]&lt;BR&gt;#else&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("coredll.dll")]&lt;BR&gt;#endif&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;public extern static IntPtr SetWindowLong(IntPtr hwnd, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;int nIndex, IntPtr dwNewLong);&lt;/P&gt;
&lt;P&gt;#if DESKTOP&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("user32.dll")]&lt;BR&gt;#else&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("coredll.dll")]&lt;BR&gt;#endif&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;public extern static IntPtr CreateWindowExW(uint dwExStyle, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;string lpClassName, string lpWindowName, uint dwStyle, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;int x, int y, int nWidth, int nHeight, IntPtr hwndParent, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;int hMenu, int hInstance, int lpParam);&lt;/P&gt;
&lt;P&gt;#if DESKTOP&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("user32.dll")]&lt;BR&gt;#else&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("coredll.dll")]&lt;BR&gt;#endif&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;public extern static int SetWindowPos(IntPtr hwnd, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;int hwndInsertAfter, int x, int y, int cx, int cy, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;uint flags);&lt;/P&gt;
&lt;P&gt;#if DESKTOP&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("user32.dll")]&lt;BR&gt;#else&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("coredll.dll")]&lt;BR&gt;#endif&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;public extern static int SetWindowText(IntPtr hwnd, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;string lpString);&lt;/P&gt;
&lt;P&gt;#if DESKTOP&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("user32.dll")]&lt;BR&gt;#else&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("coredll.dll")]&lt;BR&gt;#endif&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;public extern static IntPtr SetFocus(IntPtr hwnd);&lt;/P&gt;
&lt;P&gt;#if DESKTOP&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("user32.dll")]&lt;BR&gt;#else&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;[DllImport("coredll.dll")]&lt;BR&gt;#endif&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;public extern static int SendMessage(IntPtr hwnd, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;uint msg, uint wParam, uint lParam);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;public const int&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_NOSIZE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x0001,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_NOMOVE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x0002,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_NOZORDER&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x0004,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_NOREDRAW&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x0008,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_NOACTIVATE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x0010,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_FRAMECHANGED&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x0020,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_SHOWWINDOW&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x0040,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_HIDEWINDOW&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x0080,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_NOCOPYBITS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x0100,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_NOOWNERZORDER&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x0200,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_NOSENDCHANGING&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x0400,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_DRAWFRAME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x0020,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_NOREPOSITION&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x0200,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_DEFERERASE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x2000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SWP_ASYNCWINDOWPOS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x4000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;HWND_TOP&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;HWND_BOTTOM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 1,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;HWND_TOPMOST&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = -1,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;HWND_NOTOPMOST&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = -2,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ES_LEFT &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ES_CENTER &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0001,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ES_RIGHT &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0002,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ES_MULTILINE &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0004,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ES_UPPERCASE &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0008,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ES_LOWERCASE &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0010,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ES_PASSWORD &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0020,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ES_AUTOVSCROLL &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0040,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ES_AUTOHSCROLL &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0080,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ES_NOHIDESEL &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0100,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ES_OEMCONVERT &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0400,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ES_READONLY &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0800,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ES_WANTRETURN &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x1000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ES_NUMBER &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x2000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;GWL_EXSTYLE &amp;nbsp;&amp;nbsp;&amp;nbsp;= (-20),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;GWL_STYLE &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= (-16),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;GWL_WNDPROC &amp;nbsp;&amp;nbsp;&amp;nbsp;= (-4),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;GWL_HINSTANCE&amp;nbsp;&amp;nbsp;&amp;nbsp;= (-6),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;GWL_HWNDPARENT&amp;nbsp;&amp;nbsp;&amp;nbsp;= (-8),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;GWL_USERDATA&amp;nbsp;&amp;nbsp;&amp;nbsp;= (-21),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;GWL_ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= (-12),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WHEEL_DELTA &amp;nbsp;&amp;nbsp;&amp;nbsp;= 120,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NULL = 0x0000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CREATE = 0x0001,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_DESTROY = 0x0002,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MOVE = 0x0003,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SIZE = 0x0005,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_ACTIVATE = 0x0006,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WA_INACTIVE = 0,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WA_ACTIVE = 1,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WA_CLICKACTIVE = 2,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SETFOCUS = 0x0007,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_KILLFOCUS = 0x0008,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_ENABLE = 0x000A,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SETREDRAW = 0x000B,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SETTEXT = 0x000C,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_GETTEXT = 0x000D,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_GETTEXTLENGTH = 0x000E,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_PAINT = 0x000F,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CLOSE = 0x0010,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_QUERYENDSESSION = 0x0011,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_QUIT = 0x0012,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_QUERYOPEN = 0x0013,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_ERASEBKGND = 0x0014,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SYSCOLORCHANGE = 0x0015,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_ENDSESSION = 0x0016,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SHOWWINDOW = 0x0018,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_WININICHANGE = 0x001A,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SETTINGCHANGE = 0x001A,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_DEVMODECHANGE = 0x001B,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_ACTIVATEAPP = 0x001C,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_FONTCHANGE = 0x001D,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_TIMECHANGE = 0x001E,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CANCELMODE = 0x001F,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SETCURSOR = 0x0020,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MOUSEACTIVATE = 0x0021,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CHILDACTIVATE = 0x0022,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_QUEUESYNC = 0x0023,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_GETMINMAXINFO = 0x0024,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_PAINTICON = 0x0026,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_ICONERASEBKGND = 0x0027,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NEXTDLGCTL = 0x0028,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SPOOLERSTATUS = 0x002A,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_DRAWITEM = 0x002B,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MEASUREITEM = 0x002C,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_DELETEITEM = 0x002D,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_VKEYTOITEM = 0x002E,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CHARTOITEM = 0x002F,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SETFONT = 0x0030,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_GETFONT = 0x0031,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SETHOTKEY = 0x0032,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_GETHOTKEY = 0x0033,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_QUERYDRAGICON = 0x0037,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_COMPAREITEM = 0x0039,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_GETOBJECT = 0x003D,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_COMPACTING = 0x0041,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_COMMNOTIFY = 0x0044,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_WINDOWPOSCHANGING = 0x0046,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_WINDOWPOSCHANGED = 0x0047,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_POWER = 0x0048,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_COPYDATA = 0x004A,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CANCELJOURNAL = 0x004B,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NOTIFY = 0x004E,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_INPUTLANGCHANGEREQUEST = 0x0050,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_INPUTLANGCHANGE = 0x0051,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_TCARD = 0x0052,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_HELP = 0x0053,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_USERCHANGED = 0x0054,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NOTIFYFORMAT = 0x0055,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CONTEXTMENU = 0x007B,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_STYLECHANGING = 0x007C,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_STYLECHANGED = 0x007D,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_DISPLAYCHANGE = 0x007E,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_GETICON = 0x007F,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SETICON = 0x0080,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCCREATE = 0x0081,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCDESTROY = 0x0082,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCCALCSIZE = 0x0083,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCHITTEST = 0x0084,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCPAINT = 0x0085,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCACTIVATE = 0x0086,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_GETDLGCODE = 0x0087,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCMOUSEMOVE = 0x00A0,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCLBUTTONDOWN = 0x00A1,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCLBUTTONUP = 0x00A2,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCLBUTTONDBLCLK = 0x00A3,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCRBUTTONDOWN = 0x00A4,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCRBUTTONUP = 0x00A5,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCRBUTTONDBLCLK = 0x00A6,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCMBUTTONDOWN = 0x00A7,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCMBUTTONUP = 0x00A8,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCMBUTTONDBLCLK = 0x00A9,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_KEYFIRST = 0x0100,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_KEYDOWN = 0x0100,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_KEYUP = 0x0101,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CHAR = 0x0102,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_DEADCHAR = 0x0103,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SYSKEYDOWN = 0x0104,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SYSKEYUP = 0x0105,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SYSCHAR = 0x0106,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SYSDEADCHAR = 0x0107,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_KEYLAST = 0x0108,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_IME_STARTCOMPOSITION = 0x010D,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_IME_ENDCOMPOSITION = 0x010E,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_IME_COMPOSITION = 0x010F,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_IME_KEYLAST = 0x010F,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_INITDIALOG = 0x0110,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_COMMAND = 0x0111,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SYSCOMMAND = 0x0112,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_TIMER = 0x0113,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_HSCROLL = 0x0114,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_VSCROLL = 0x0115,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_INITMENU = 0x0116,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_INITMENUPOPUP = 0x0117,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MENUSELECT = 0x011F,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MENUCHAR = 0x0120,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_ENTERIDLE = 0x0121,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CHANGEUISTATE = 0x0127,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_UPDATEUISTATE = 0x0128,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_QUERYUISTATE = 0x0129,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CTLCOLORMSGBOX = 0x0132,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CTLCOLOREDIT = 0x0133,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CTLCOLORLISTBOX = 0x0134,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CTLCOLORBTN = 0x0135,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CTLCOLORDLG = 0x0136,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CTLCOLORSCROLLBAR = 0x0137,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CTLCOLORSTATIC = 0x0138,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MOUSEFIRST = 0x0200,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MOUSEMOVE = 0x0200,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_LBUTTONDOWN = 0x0201,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_LBUTTONUP = 0x0202,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_LBUTTONDBLCLK = 0x0203,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_RBUTTONDOWN = 0x0204,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_RBUTTONUP = 0x0205,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_RBUTTONDBLCLK = 0x0206,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MBUTTONDOWN = 0x0207,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MBUTTONUP = 0x0208,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MBUTTONDBLCLK = 0x0209,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCMOUSEHOVER = 0x02A0,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NCMOUSELEAVE = 0x02A2,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MOUSEWHEEL = 0x020A,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MOUSELAST = 0x020A,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_PARENTNOTIFY = 0x0210,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_ENTERMENULOOP = 0x0211,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_EXITMENULOOP = 0x0212,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_NEXTMENU = 0x0213,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SIZING = 0x0214,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CAPTURECHANGED = 0x0215,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MOVING = 0x0216,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_POWERBROADCAST = 0x0218,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_DEVICECHANGE = 0x0219,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_IME_SETCONTEXT = 0x0281,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_IME_NOTIFY = 0x0282,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_IME_CONTROL = 0x0283,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_IME_COMPOSITIONFULL = 0x0284,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_IME_SELECT = 0x0285,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_IME_CHAR = 0x0286,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_IME_KEYDOWN = 0x0290,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_IME_KEYUP = 0x0291,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MDICREATE = 0x0220,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MDIDESTROY = 0x0221,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MDIACTIVATE = 0x0222,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MDIRESTORE = 0x0223,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MDINEXT = 0x0224,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MDIMAXIMIZE = 0x0225,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MDITILE = 0x0226,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MDICASCADE = 0x0227,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MDIICONARRANGE = 0x0228,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MDIGETACTIVE = 0x0229,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MDISETMENU = 0x0230,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_ENTERSIZEMOVE = 0x0231,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_EXITSIZEMOVE = 0x0232,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_DROPFILES = 0x0233,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MDIREFRESHMENU = 0x0234,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MOUSEHOVER = 0x02A1,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_MOUSELEAVE = 0x02A3,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CUT = 0x0300,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_COPY = 0x0301,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_PASTE = 0x0302,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CLEAR = 0x0303,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_UNDO = 0x0304,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_RENDERFORMAT = 0x0305,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_RENDERALLFORMATS = 0x0306,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_DESTROYCLIPBOARD = 0x0307,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_DRAWCLIPBOARD = 0x0308,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_PAINTCLIPBOARD = 0x0309,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_VSCROLLCLIPBOARD = 0x030A,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_SIZECLIPBOARD = 0x030B,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_ASKCBFORMATNAME = 0x030C,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_CHANGECBCHAIN = 0x030D,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_HSCROLLCLIPBOARD = 0x030E,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_QUERYNEWPALETTE = 0x030F,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_PALETTEISCHANGING = 0x0310,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_PALETTECHANGED = 0x0311,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_HOTKEY = 0x0312,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_PRINT = 0x0317,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_PRINTCLIENT = 0x0318,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_HANDHELDFIRST = 0x0358,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_HANDHELDLAST = 0x035F,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_AFXFIRST = 0x0360,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_AFXLAST = 0x037F,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_PENWINFIRST = 0x0380,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_PENWINLAST = 0x038F,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_APP = unchecked((int)0x8000),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_USER = 0x0400,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WM_REFLECT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = WM_USER + 0x1C00,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WMSZ_LEFT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 1,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WMSZ_RIGHT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 2,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WMSZ_TOP&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 3,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WMSZ_TOPLEFT&amp;nbsp;&amp;nbsp;&amp;nbsp;= 4,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WMSZ_TOPRIGHT&amp;nbsp;&amp;nbsp;&amp;nbsp;= 5,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WMSZ_BOTTOM &amp;nbsp;&amp;nbsp;&amp;nbsp;= 6,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WMSZ_BOTTOMLEFT &amp;nbsp;&amp;nbsp;= 7,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WMSZ_BOTTOMRIGHT&amp;nbsp;&amp;nbsp;= 8,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_OVERLAPPED&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_POPUP&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= unchecked((int)0x80000000),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_CHILD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x40000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_MINIMIZE &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x20000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_VISIBLE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x10000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_DISABLED &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x08000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_CLIPSIBLINGS &amp;nbsp;&amp;nbsp;= 0x04000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_CLIPCHILDREN &amp;nbsp;&amp;nbsp;= 0x02000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_MAXIMIZE &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x01000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_CAPTION&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00C00000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_BORDER&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00800000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_DLGFRAME &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00400000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_VSCROLL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00200000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_HSCROLL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00100000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_SYSMENU&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00080000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_THICKFRAME&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00040000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_GROUP&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00020000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_TABSTOP&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00010000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_MINIMIZEBOX&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00020000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_MAXIMIZEBOX&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00010000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_TILED&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_ICONIC&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x20000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_SIZEBOX&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00040000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_OVERLAPPEDWINDOW &amp;nbsp;= (0x00000000|0x00C00000|0x00080000|0x00040000|0x00020000|0x00010000),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_POPUPWINDOW&amp;nbsp;&amp;nbsp;&amp;nbsp;= (unchecked((int)0x80000000)|0x00800000|0x00080000),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_CHILDWINDOW&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x40000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_DLGMODALFRAME &amp;nbsp;= 0x00000001,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_NOPARENTNOTIFY&amp;nbsp;= 0x00000004,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_TOPMOST&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00000008,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_ACCEPTFILES&amp;nbsp;&amp;nbsp;= 0x00000010,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_TRANSPARENT&amp;nbsp;&amp;nbsp;= 0x00000020,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_MDICHILD&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00000040,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_TOOLWINDOW&amp;nbsp;&amp;nbsp;= 0x00000080,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_WINDOWEDGE&amp;nbsp;&amp;nbsp;= 0x00000100,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_CLIENTEDGE&amp;nbsp;&amp;nbsp;= 0x00000200,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_CONTEXTHELP&amp;nbsp;&amp;nbsp;= 0x00000400,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_RIGHT &amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00001000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_LEFT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_RTLREADING&amp;nbsp;&amp;nbsp;= 0x00002000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_LTRREADING&amp;nbsp;&amp;nbsp;= 0x00000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_LEFTSCROLLBAR &amp;nbsp;= 0x00004000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_RIGHTSCROLLBAR&amp;nbsp;= 0x00000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_CONTROLPARENT &amp;nbsp;= 0x00010000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_STATICEDGE&amp;nbsp;&amp;nbsp;= 0x00020000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_APPWINDOW &amp;nbsp;&amp;nbsp;= 0x00040000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_OVERLAPPEDWINDOW&amp;nbsp;= (0x00000100|0x00000200),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_PALETTEWINDOW &amp;nbsp;= (0x00000100|0x00000080|0x00000008),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_LAYERED&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x00080000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_NOINHERITLAYOUT&amp;nbsp;= 0x00100000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_LAYOUTRTL &amp;nbsp;&amp;nbsp;= 0x00400000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WS_EX_NOACTIVATE&amp;nbsp;&amp;nbsp;= 0x08000000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_SETVIEW&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 284,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_CANPASTE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 50,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_CANREDO&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 246,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_CLEARALL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 331,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_GETPAGESTYLE&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 323,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_GETPENMODE&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 328,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_GETVIEW&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 254,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_GETWRAPMODE&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 227,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_GETZOOMPERCENT&amp;nbsp;&amp;nbsp;= WM_USER + 289,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_INSERTLINKS&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 333,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_REDOEVENT&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 235,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_SETINKLAYER&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 288,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_SETPAGESTYLE&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 287,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_SETPENMODE&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 329,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_SETVIEWATTRIBUTES&amp;nbsp;= WM_USER + 332,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_SETWRAPMODE&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 319,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_SETZOOMPERCENT&amp;nbsp;&amp;nbsp;= WM_USER + 290,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_STREAMIN&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 73,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_STREAMOUT&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 74,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EM_UNDOEVENT&amp;nbsp;&amp;nbsp;&amp;nbsp;= WM_USER + 234,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;VT_TYPINGVIEW&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;VT_WRITINGVIEW&amp;nbsp;&amp;nbsp;&amp;nbsp;= 2,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;VT_DRAWINGVIEW&amp;nbsp;&amp;nbsp;&amp;nbsp;= 3,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;VL_SMARTINK&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp; 0,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;VL_WRITINGINK&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp; 1,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;VL_DRAWINGINK&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp; 2,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;VL_LINKS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp; 3,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;VL_SMARTLINKS&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp; 4,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PS_LEFTMARGIN&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0000,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PS_TOPMARGIN&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0001,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PS_RULEDLINES&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0002,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PS_GRIDLINES&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0004,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PS_TOPLEFTMARGIN&amp;nbsp;&amp;nbsp;= 0x0008,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PS_NONE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0010,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PS_DOTTEDLINES&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0x0020,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PS_YELLOWBACKGROUND&amp;nbsp;&amp;nbsp;= 0x0040,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;MODE_PEN&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 0,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;MODE_SELECT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 1,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;MODE_SPACE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 2;&lt;BR&gt;&amp;nbsp;}&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[Author: Katie Blanch]&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Disclaimers:&lt;BR&gt;This posting is provided "AS IS" with no warranties, and confers no rights.&lt;BR&gt;Some of the information contained within this post may be in relation to beta software.&amp;nbsp;Any and all details are subject to change.&lt;/EM&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=442616" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/netcfteam/archive/tags/Author_3A00_+Katie+Blanch/default.aspx">Author: Katie Blanch</category></item><item><title>Interop: Common Issues &amp; Debugging Techniques</title><link>http://blogs.msdn.com/netcfteam/archive/2005/07/24/442612.aspx</link><pubDate>Sun, 24 Jul 2005 10:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:442612</guid><dc:creator>NetCFTeam</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/netcfteam/comments/442612.aspx</comments><wfw:commentRss>http://blogs.msdn.com/netcfteam/commentrss.aspx?PostID=442612</wfw:commentRss><description>&lt;P&gt;&lt;FONT color=#000080 size=5&gt;&lt;STRONG&gt;Interop: Common Issues and Debugging Techniques&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This post will describe some of the types of problems that can arise when interoperating between managed and native code using the .Net Compact Framework Version 2. An overview of how the runtime works under the scenes is also given, which may help promote better quality and more efficient code as well as give insight into the cause of problems. &lt;/P&gt;
&lt;P&gt;&lt;FONT color=#808080 size=5&gt;&lt;STRONG&gt;Marshaling&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;When interoperating with native code, a conversion process is necessary to translate argument data between managed and native code. The .Net Compact Framework supports marshaling many different managed types, both to and from native code. Each managed type that is supported has default marshaling behavior, which may be different depending on the type of call being made (COM interface function call, delegate callback, or PInvoke). You can also override the default marshaling behavior by using the MarshalAs attribute. The runtime will marshal (or convert) data automatically when an interop function call is made, as specified in the managed PInvoke signature, delegate callback signature, or COM interface signature. You can also use the functions in the InteropServices.Marshal class to manually convert data between managed objects and an IntPtr representing the native object. For some examples, see GetIUnknownForObject, GetObjectForIUnknown, PtrToStringBSTR, StringToBSTR, StructureToPtr, or PtrToStructure. &lt;/P&gt;
&lt;P&gt;There are a few types of issues that come up when interoperating with native code that involve the marshaling process:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color=#ff0000&gt;1. A managed NotSupportedException may be thrown, due to an unsupported type being specified as an argument or return value in the managed interop signature.&lt;/FONT&gt; &lt;BR&gt;&lt;/STRONG&gt;Although almost all parameter types the desktop framework supports are now supported in the .Net Compact Framework, there are a few situations where there is limited support. These exceptions include fields in structures, elements in arrays, and return types. The workaround for these limitations is to use the functions in the InteropServices.Marshal class to manually do the conversion process, and specify an IntPtr as the type in the signature or structure.&lt;BR&gt;Interoperating using methods, types, or COM interface classes that are generic is also not supported.&lt;BR&gt;The interop log file will specify the particular method causing the issue, which can be especially useful when using COM interfaces. The best way to diagnose this is to isolate the unsupported type by systematically changing parameter types to IntPtr or a known supported type. Once the unsupported type is identified, consider using another similar type or doing the conversion work manually.&amp;nbsp; &lt;BR&gt;If the unsupported type is identified to be a structure, removing the MarshalAs specifier for structure fields may solve the issue (assuming you can specify a field type that has the appropriate default marshaling behavior).&amp;nbsp; .NetCF will allow only a few limited cases of using the MarshalAs attribute to change the default marshaling behavior of a field in a structure.&amp;nbsp; You can also consider using IntPtr marshaling using the various functions in the InteropServices.Marshal class.&lt;BR&gt;See the resources section for more information about how to determine what the default marshaling behavior is for a particular type.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color=#ff0000&gt;2. The native function call may not produce the expected results or causes a native exception, due to types being marshaled incorrectly and not matching the specifications of the native function signature.&lt;/FONT&gt;&lt;BR&gt;&lt;/STRONG&gt;The best way to diagnose these types of issues is to use the signature output in the interop log file and compare how the runtime is marshaling parameters to what is expected by the native function. &lt;BR&gt;You can then change the types used in the managed signature or use the MarshalAs attribute to ensure data is marshaled correctly. Keep in mind the default marshaling behavior of a particular type will sometimes be different depending on the type of interop call (PInvoke, Com, Delegate callback).&amp;nbsp; The ref keyword must also be applied correctly to the parameters in the managed interop signature. In the event the signature takes a structure parameter, you should also make sure the structure alignment is specified correctly using the StructLayout attribute.&lt;BR&gt;Other common marshaling errors include using a managed 'bool' instead of an 'int'&amp;nbsp;to represent&amp;nbsp;a native Win32 BOOL type.&amp;nbsp; Likewise, an managed 'long' is actually 64 bits and is not equalivant to a Win32 LONG, which is 32 bits.&lt;/P&gt;
&lt;P&gt;The .Net Compact Framework has two differences from the desktop framework with regard to default marshaling of types for a PInvoke call, for backward compat reasons.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;An 'object' in the managed signature will not marshal into&amp;nbsp;a by value variant, but instead will be 'NULL'.&amp;nbsp; You can override this behavior by using MarshalAs(UnmanagedType.Struct) in your PInvoke signature, which will cause the object to be marshaled as a variant under both .NetCF and the desktop. 
&lt;LI&gt;A class in the managed signature will not marshal into a CCW, but instead will result in a pointer to a structure in native code.&amp;nbsp; You can override this behavior by using MarshalAs(UnmanagedType.Interface) in your PInvoke signature, which will cause the object to be marshaled as a CCW under both .NetCF and the desktop.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color=#ff0000&gt;3. A native exception occurs after the native function has returned or at inconsistent times, due to improper use of runtime memory by the native code.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR&gt;During the marshaling process, the runtime will sometimes place the parameter data inside a temporary buffer or temporarily on the stack. For this reason, it is not always safe for native code to hold a reference to the memory containing marshaled data. Although, in some cases this will work with our current implementation depending on the particular types marshaled, it is recommended that native code always copy data into its own buffer when marshaling any complex types. &lt;BR&gt;If you must avoid copying data, use an IntPtr in your managed interop signature. In the event you are passing a pointer associated with managed object data to native code that will live beyond the return of the native function call, be aware that the GC can cause objects to move around. It is recommended that you maintain a pinned reference to the object, by using a GCHandle.&lt;BR&gt;When returning from a native function call, the marshaler will free native memory associated with arguments after the back propagation into the managed object has completed. This includes cases where only out-marshaling has occurred as well as cases where the content pointed to has changed while in the native function. The runtime will use CoTaskMemFree (or SysFreeString in the case of BSTRs), and expects any non-null memory returned to have been allocated with CoTaskMemAlloc. When necessary, the runtime will free both the original data allocated during the in-marshaling process, and the new data allocated inside the native function call. To avoid this behavior, you can use IntPtr in the managed interop signature, in which case you are then responsible for cleaning up the memory yourself. The types that are affected by this include, but are not limited to, Formatted Classes, Strings, StringBuilders, and Arrays. &lt;BR&gt;You must also use IntPtr marshaling when interacting with native APIs that will return data from the middle of an allocated buffer, such as VerQueryValue. You can see more information about cases where IntPtr marshaling may be necessary for certain APIs here:&lt;BR&gt;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconmemorymanagement.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconmemorymanagement.asp&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;&lt;STRONG&gt;4. There appears to be a memory leak when using BSTR marshaling, due to a native cache in the Windows CE OS.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR&gt;The memory used for BSTR allocations is cached, so a BSTR is not always freed completely upon a call to SysFreeString. There is currently no way to turn this cache off under Windows CE, and given the low memory conditions of embedded devices this may present itself as an unacceptable memory leak. To work around this issue, consider using CoTaskMemFree instead of SysFreeString, which prevents any free space in the cache from accumulating. &lt;/P&gt;
&lt;P&gt;The runtime will use SysFreeString under two conditions:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;During the marshaling process when you specify MarshalAs(UnmanagedType.BSTR) for a parameter, array element, or structure field. You can prevent this from happening by using IntPtr marshaling, and manually converting strings to BSTRs before calling the native function using InteropServices.Marshal.StringToBSTR.&amp;nbsp; 
&lt;LI&gt;The Marshal.FreeBSTR managed API maps directly to SysFreeString. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;The native COM component being used will also need to be screened for SysFreeString use.&lt;BR&gt;You can see some more information about the BSTR cache here:&lt;BR&gt;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/automat/htm/chap7_2xgz.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/automat/htm/chap7_2xgz.asp&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#808080 size=5&gt;&lt;STRONG&gt;Making Native function calls from Managed code&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;There are 2 main types of managed to native function calls:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;PInvoke - Using the DLLImport attribute, a signature is defined in managed code that corresponds to an exported function in a native .dll.&amp;nbsp; 
&lt;LI&gt;COM interface method call - a Runtime Callable Wrapper (RCW) object is instantiated in managed code that wraps a native COM object and then cast to a managed interface describing the native COM interface. 
&lt;UL&gt;
&lt;LI&gt;COM VTable call - For interfaces that are declared as Dual or IUnknown, the runtime will call the method directly through the VTable. 
&lt;LI&gt;COM Dispatch call - For interfaces that are declared as pure IDispatch, the runtime will call the method through the use of IDispatch-&amp;gt;Invoke.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;In all three of these cases, there is a stub generated that converts between the managed calling convention and the native calling convention. In order to create this stub, the signature of the PInvoke or COM interface method is processed and any error checking that only requires knowledge of the parameter types and not the actual data occurs.&lt;BR&gt;During runtime when the function is called and this stub is executed, the arguments are in-marshaled as specified, then the native function is called, and finally the out-marshaling occurs along with some runtime post-processing, cleanup, and error handling. If an exception occurs during the in-marshaling process, the native function will not be called.&lt;BR&gt;If a native function call is considered PreserveSig(false), the runtime will assume the native function returns a HResult. In the event that a failure HResult is returned, the runtime will translate this into a managed exception, and managed objects used as parameters will not necessarily be modified or initialized during the out-marshaling process as normal. In this case, you must also keep in mind that the managed signature will not look exactly like the native signature. You can use interop logging to determine the exact native signature the runtime will be expecting. For COM calls PreserveSig defaults to false, where as for PInvoke calls it defaults to true, if not explicitly specified.&lt;/P&gt;
&lt;P&gt;Knowledge of this process can help you diagnose and handle a few common issues:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color=#ff0000&gt;5. A MissingMethodException occurs when trying to call a PInvoke function, due to the .dll not being found by the runtime or because the function requested is not exported as specified in the native .dll.&lt;BR&gt;&lt;/FONT&gt;&lt;/STRONG&gt;In this case, the exception occurs at stub generation time rather then at runtime. Normally a PInvoke function is jitted upon its first call, however you can use the Marshal.PreLink function to force the runtime to jit the stub, allowing you to handle these cases smoothly in managed code and present the user with an appropriate message.&lt;BR&gt;If the runtime is failing to find the native .dll, ensure it is present and consider writing a simple native application that calls LoadLibraryW to load the .dll. In some cases under generic windows CE, a native .dll may have a dependency on the components of the image, and may fail to load if the dependencies are not present in the image.&lt;BR&gt;If the runtime is failing to find the particular exported function in the native .dll, ensure the function is present and properly exported using the dumpbin utility as described here: &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/netcfdumpbinpinvoke.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/netcfdumpbinpinvoke.asp&lt;/A&gt;. Keep in mind, you can reference the exported functions either by ordinal or name. &lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;&lt;STRONG&gt;6. A managed exception occurs when calling a native function from managed code, due to a runtime marshaling issue.&lt;BR&gt;&lt;/STRONG&gt;&lt;/FONT&gt;In the case a PInvoke function call is being made, it is worthwhile to use Marshal.PreLink and ensure no exceptions are thrown. This will rule out jit-time errors that occur when the stub is generated, such as those resulting from unsupported marshaling types. Some marshaling issues will not occur until the function is called and the actual conversion work happens. These typically happen when trying to convert a native object into a managed object, either during the out-marshaling process of a managed to native function call, or during the in-marshaling process of a native to managed call. Some types have specific ranges in which the data is valid, such as the case with the DateTime type. In the case of VARIANTs, the runtime many not be able to coerce the type specified inside the native variant to the managed type specified in the function signature. &lt;BR&gt;The best practice to diagnose these issues is to use a process of elimination to determine the particular parameter causing the issue. You can use the [in] and [out] attributes to prevent marshaling in a particular direction for each parameter. &lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;&lt;STRONG&gt;7. A native COM function results in an unexpected managed exception or the native function behaves incorrectly, due to the managed COM interface signatures being incorrect with regard to the PreserveSig attribute.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR&gt;If the PreserveSig attribute is used incorrectly, the runtime will assume an incorrect native signature and may call the function with un-initialized parameters, or interpret the return valid as a failure HResult when the native function does not return a HResult. &lt;BR&gt;The interop log file will reveal the expected native signature, and this should be compared to the documentation associated with the COM interface.&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#808080 size=5&gt;&lt;STRONG&gt;Making Managed function calls from Native code&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;There are 2 main types of native to managed function calls:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Delegate Callbacks - You can marshal a delegate down to native code as a function pointer 
&lt;LI&gt;COM interface method call - a Com Callable Wrapper (CCW) is associated with a managed object and used to expose interfaces that object implements to native code. 
&lt;UL&gt;
&lt;LI&gt;COM VTable call - For interfaces that are declared as Dual or IUnknown, native code can directly call managed methods 
&lt;LI&gt;COM Dispatch call - For interfaces that are declared as pure IDispatch and Dual, native code can call managed methods through the use of IDispatch-&amp;gt;Invoke.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;The process for making callbacks from native code into managed code is similar to the other direction. Both stub generation errors and runtime errors are possible. Likewise, based on the PreserveSig attribute, the runtime may translate managed exceptions to HResults. If the managed function call is considered PreserveSig(false) and an uncaught exception occurs while in managed code, the runtime will return a HResult associated with the exception to the native caller. For COM calls PreserveSig defaults to false, where as for delegate callbacks it results to true, if not explicitly specified. If a COM call is marked as PreserveSig(true) and the managed signature returns a 4-byte value such as an int, the runtime will still translate any uncaught exceptions to a HResult.&lt;BR&gt;The .Net Compact Framework does not support hosting the runtime from native code. This means that you will not be able to call CoCreateInstace to instantiate a managed object, or register managed objects as COM objects on the system. You will also not be able to call CorBindToRuntime or ClrCreateManagedInstance. In order to call managed functions from native code, you must first use the runtime to marshal a managed interface or a delegate down to native code. This means you must always start out in managed code (with a .net executable) in order to expose .net components to native code.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color=#ff0000&gt;8. A native exception occurs when attempting to call a Delegate callbacks from native code, due to the managed delegate being finalized.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR&gt;When using delegate callbacks, you often first make a PInvoke call to register the callback function pointer which will be used after the original PInvoke call returns. Because the generated stub associated with the callback stub is cleaned up when a delegate is finalized, you must ensure the delegate object stays alive until it will no longer be used by native code. Simply keeping a reference to the delegate in managed code will be enough to keep it alive (there is no need to pin the delegate object).&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color=#ff0000&gt;9. Native code that uses native to managed function calls is behaving unexpectedly because of a managed exception firing or runtime marshaling errors, due to interface signatures being incorrect with regard to the PreserveSig attribute.&lt;BR&gt;&lt;/FONT&gt;&lt;/STRONG&gt;When a managed exception occurs inside a managed function call that is not caught before the call returns, operating under PreserveSig(false) is the only way to ensure this exception will be translated to a HResult and properly returned from the managed call so native code can handle the error. If operating under preserveSig(true), it is recommended that you wrap a try/catch around your exposed managed function to ensure there are no uncaught exceptions and handle any errors in managed code since native code will not be able to know there was an error or handle it properly. Also keep in mind, that an exception can also occur due to a runtime marshaling error and cause the managed function to not be called. &lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;&lt;STRONG&gt;10. A CCW function call works when called through the VTable, but not when called through IDispatch-&amp;gt;Invoke despite the interface being marked as InterfaceIsDual, due to missing or improper use of attributes.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR&gt;Individual methods, as well as interfaces, can be marked ComVisible. When a method is marked ComVisible(false), a VTable stub is still generated for it allowing it to be called directly through the VTable, but it is protected from being called through IDispatch-&amp;gt;Invoke. In the case of properties, the individual get or set method is checked, as well as the property declaration itself.&lt;BR&gt;If native code calls QueryInterface requesting a pure IDispatch pointer, the runtime will return the interface that it has determined is the 'default interface' that supports IDispatch.&amp;nbsp; Typically, under the desktop framework this resolves to the class interface and exposes all methods to native code.&amp;nbsp; Under .NetCF, since class interfaces are not automatically generated, this will resolve to the first interface present in metadata that the class implements which supports IDispatch.&amp;nbsp; It's recommended that you explicitly declare a default interface using the ComDefaultInterfaceAttribute.&amp;nbsp; &lt;BR&gt;For methods to be exposed through IDispatch, they must be explicitly marked with the DispIdAttribute.&lt;BR&gt;If native code is relying on IDispatch-&amp;gt;GetIDsOfNames to resolve methods, there are a couple of limitations.&amp;nbsp; The interop log file will contain more detailed output if unsupported functionallity is being requested or an error is being returned to native code from GetIDsOfNames.&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#808080 size=5&gt;&lt;STRONG&gt;COM Interop&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;The .Net Compact Framework supports interoperating with native COM objects from managed code as well as allowing native code to interact with managed objects using COM.&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Runtime Callable Wrappers (RCWs) - these are used to allow managed code to call native COM object functions. 
&lt;UL&gt;
&lt;LI&gt;There are 3 ways to create an RCW: 
&lt;UL&gt;
&lt;LI&gt;You can use a tool called tlbimp to import a type library (shipped with the native COM object), and spit out a managed .dll. This managed .dll will contain a bunch of interfaces associated with the native COM interfaces supported by the object. It will also contain a managed class (with a guid and ComImport attribute specified) that is associated with the actual COM object. When this managed class is instantiated, the runtime will make a call to CoCreateInstance and instantiate the native COM object. Using this method requires that the native COM object has been properly registered with the system and the guid is present in the registry for lookup. 
&lt;LI&gt;You can then use the following code to manually instantiate an object&lt;BR&gt;&lt;BR&gt;Type t = Type.GetTypeFromCLSID(new Guid("2CD19942-4103-4dcc-A75C-57DF5814C611") ); // This guid is associated with the COM object itself, not the native COM interfaces you'd like to use to interact with the object&lt;BR&gt;&lt;BR&gt;Object obj = Activator.CreateInstance(t); // This causes the runtime to call CoCreateInstance&lt;BR&gt;&lt;BR&gt;Alternatively, you can use Type.GetTypeFromProgID to use the registry to resolve a string into a GUID associated with a native COM object. &lt;BR&gt;Using this method requires that the native COM object has been properly registered with the system and the guid and\or progID is present in the registry for lookup. 
&lt;LI&gt;You can also create an RCW object via marshaling when making a managed to native call that causes a COM object to be out-marshaled. For example, a native .dll can have a 'CreateComObject' exported function that returns a native COM object, and therefore doesn't require the native COM object to be registered by the system.&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;The runtime will hide many of the rules that are required when using native COM objects. For example, you don't need to manually call QueryInterface in managed code. Simply casting an RCW object to a particular interface causes the runtime to do a QueryInterface under the scenes, and a managed InvalidCast exception is thrown if the native COM object doesn't support the guid associated with the casted interface. The runtime also handles the reference counting details.&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Com Callable Wrappers (CCWs) - these are used to allow native code to call managed functions exposed through COM interfaces. 
&lt;UL&gt;
&lt;LI&gt;CCWs are created when an object is marshaled down to native code as an interface. Once in native code, other interfaces can be retrieved using QueryInterface, including a number of runtime implemented interfaces such as IConnectionPointContainer. You can call managed functions directly through the VTable, or through IDispatch-&amp;gt;Invoke depending on the type of COM interface as declared in managed code. The native code must abide by normal reference counting and COM rules when interacting with CCWs.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;TlbImp is the only tool supported under the .Net Compact Framework. While the use of other tools, such as AxImp, and TlbExp may work in some cases, they are not tested and may not always produce code that will run without modification under the .Net Compact Framework.&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;&lt;STRONG&gt;11. There appears to be a memory leak when using COM interop features, due to Runtime Callable Wrappers not being freed immediately.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR&gt;Normally, RCWs are freed upon finalization when the managed object associated with the native COM object is no longer in use and the GC starts collecting object memory. At this point, the original object returned from CoCreateInstance is Released, along with any interface pointers that the runtime called QueryInterface to retrieve.&lt;BR&gt;Marshal.ReleaseComObject and Marshal.FinalReleaseComObject can be used to manage the lifetime of an RCW manually. Keep in mind that once these are used you will not be able to make native COM interface method calls using the object any longer and will receive an exception upon attempting to do so.&lt;BR&gt;There is also a native bug in Windows CE TypeLib support that can cause a memory leak when a native COM object that uses LoadTypeLib or LoadRegTypeLib is freed from a thread other then the one it was created on, including the thread finalizers are run on. In this case, it is highly recommended you use the marshal class functions to manually release the native COM object.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color=#ff0000&gt;12. A native control doesn't appear properly or doesn't work properly when using COM interop features to host an ActiveX control in a managed Form, due to a bad ActiveX container implementation.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR&gt;Be sure to review the following references and understand how to write a container in native code. &lt;BR&gt;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/workshop/components/containers/overview/containers.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/workshop/components/containers/overview/containers.asp&lt;/A&gt;&lt;BR&gt;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/workshop/components/activex/intro.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/workshop/components/activex/intro.asp&lt;/A&gt;&lt;BR&gt;It is also recommended that you create a simple native ActiveX control to test your container with (possibly using the Visual Studio MFC wizard), which will allow you to debug into the native source of the control. &lt;BR&gt;When debugging an ActiveX container implementation, it may helpful to examine the interop log file for cases where native code called QueryInterface and received an E_NOINTERFACE return value. This can help you diagnose when a required interface was not implemented by the container.&lt;BR&gt;If the application is running, but the control doesn't appear in the form, use the Remote Spy tool to examine the window hierarchy and position/sizing of the native control and its parents.&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;&lt;STRONG&gt;13. A native exception or memory leak occurs when using Com Callable Wrappers to provide native code an interface mapping to managed functions, due to improper reference counting logic.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR&gt;A CCW will be cleaned up upon the last reference count release from native code. Native code is expected to release any interfaces it acquired from a call to QueryInterface, as well as other functions that return an interface (such as IConnectionPointContainer::FindConnectionPoint for example). &lt;BR&gt;If native code wishes to keep a reference to a CCW beyond the return from the PInvoke where a CCW was marshaled down, the particular interface desired should be retrieved through QueryInterface. When the PInvoke returns and the out-marshaling process completes, the CCW will be cleaned up if there are no outstanding references.&lt;BR&gt;When using the runtime implemented connection point interfaces to allow native code to get notified when a managed event fires, the runtime will increment the CCW reference count upon a call to IConnectionPoint::Advise. Native code must call IConnectionPoint::Unadvise when it no longer wishes to be notified of managed events firing or the CCW will not be cleaned up.&lt;BR&gt;You can use the Marshal Class functions to retrieve an IntPtr representing an interface from a managed object (See GetIUnknownForObject), You can also examine the&amp;nbsp;current reference count for&amp;nbsp;an IntPtr representing an interface (including a CCW) by using Marshal.AddRef and Marshal.Release (which both return the current reference count).&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;&lt;STRONG&gt;14. A managed exception occurs when instantiating or using a Runtime Callable Wrapper or a Com Callable Wrapper despite the same code working on the desktop framework, due to limitations in com interop support under the .Net Compact Framework.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR&gt;The interop log file will often contain more detailed information about the cause of an exception that occurs due to differences in COM interop support between the desktop framework and the .Net Compact framework. &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The .Net Compact Framework does not support class interfaces. Under the desktop, a class interface will be automatically generated for any managed objects exposed as CCWs to native code, allowing you to directly access any field members or functions present in the class. Under the .Net Compact Framework, all functionality you wish to expose must be wrapped in an interface. It is also recommended that you explicitly mark classes as ClassInterfaceType.None using the ClassInterfaceAttribute, when passing classes directly to native code. 
&lt;LI&gt;The .Net Compact Framework will not automatically generate a guid for interfaces lacking an explicitly defined guid. If an interface is marked ComVisible(true) and is exposed to native code, it must also have a guid specified or an exception will occur. 
&lt;LI&gt;The .Net Compact Framework does not allow you to inherit from an interop assembly class generated through the use of tlbimp. 
&lt;LI&gt;The .Net Compact Framework does not support STAThread COM initialization, because Windows Mobile does not allow you to initialize COM in this way. 
&lt;LI&gt;The .Net Compact Framework has some marshaling support differences from the desktop framework. 
&lt;LI&gt;The .Net Compact Framework has marked all base class libraries as ComVisible(false) at the assembly level, which requires developers to wrap any BCL functionality they wish to expose to native code. 
&lt;LI&gt;The .Net Compact Framework has some subtle differences in the logic to determine COM visibility for interfaces. 
&lt;UL&gt;
&lt;LI&gt;Any generic or open type interfaces are automatically not visible to COM. 
&lt;LI&gt;Any classes marked as ComImport are visible to COM. 
&lt;LI&gt;Any classes without the public access modifier are considered to be not visible to COM. 
&lt;LI&gt;Finally the class is checked the ComVisible attribute. If it is not present, the assembly is checked for the ComVisible attribute. If the ComVisible attribute is not declared then the default is ComVisible(true). 
&lt;LI&gt;This logic is shared between RCWs and CCWs. 
&lt;UL&gt;
&lt;LI&gt;For the RCW case, if an interface is not considered to be visible to COM, then you will not be able to cast to it. (The runtime will not attempt to call QueryInterface on the native COM object associated with the RCW object). 
&lt;LI&gt;For the CCW case, if an interface is not considered to be visible to COM, then native code will not be able to successfully call QueryInterface requesting it. Developers will also not be able to marshal an interface not visible to COM down to native code.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color=#ff0000&gt;15. A managed InvalidComObjectException occurs when using a Runtime Callable Wrapper to call a native COM function, due to the Runtime Callable Wrapper having been freed previously.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR&gt;If the application has used Marshal.ReleaseComObject or Marshal.FinalReleaseComObject, you will not be able to make native COM interface method calls using the object any longer. If an attempt to do this has been made upon a previously valid RCW object, the interop log file will contain an error message.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color=#ff0000&gt;16. A managed InvalidComObjectException occurs when attempting to instantiate a Com Callable Wrapper, due to the use of a type that requires an unsupported marshaling feature.&lt;BR&gt;&lt;/FONT&gt;&lt;/STRONG&gt;When a CCW is constructed, the object's entire interface hierarchy is walked by the runtime. All interface methods visible to COM that are implemented will have a stub generated for them to allow the managed function call from native code. If the runtime cannot marshal any parameter type for any method, the entire CCW will not be able to be constructed. The interop log file will contain more information specifying the exact method containing the issue.&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#808080 size=5&gt;&lt;STRONG&gt;Resources&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;With regard to COM interop support, it may be useful to understand both the rules around using and building native COM objects, as well as how COM is integrated and supported in the .Net runtime. I like the following sources:&lt;BR&gt;1) Inside COM, by Dale Rogerson (red book)&lt;BR&gt;2) .Net and COM, by Adam Nathan (blue book)&lt;/P&gt;
&lt;P&gt;All applications should be tested with Interop Logging turned on, even if there are no known issues. This will produce a log file that should then be searched for 'ERROR' and 'WARNING'. The log file will contain more information about the cause of managed exceptions, subtle errors that do not manifest themselves as managed exceptions, as well as assist in debugging interop issues involving native code for which the source is unavailable.&lt;BR&gt;&lt;a href="http://blogs.msdn.com/netcfteam/archive/2005/07/24/442609.aspx"&gt;http://blogs.msdn.com/netcfteam/archive/2005/07/24/442609.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;There are interop related guidelines and tips that can drastically improve your application's performance: &lt;a href="http://blogs.msdn.com/netcfteam/archive/2005/05/04/414820.aspx"&gt;http://blogs.msdn.com/netcfteam/archive/2005/05/04/414820.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Default marshaling for various types:&lt;BR&gt;Arrays: &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondefaultmarshalingforarrays.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondefaultmarshalingforarrays.asp&lt;/A&gt;&lt;BR&gt;Boolean: &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondefaultmarshalingforbooleans.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondefaultmarshalingforbooleans.asp&lt;/A&gt;&lt;BR&gt;Classes: &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondefaultmarshalingforclasses.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondefaultmarshalingforclasses.asp&lt;/A&gt;&lt;BR&gt;Value Types / Structs: &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondefaultmarshalingforvaluetypes.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondefaultmarshalingforvaluetypes.asp&lt;/A&gt;&lt;BR&gt;Strings: &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondefaultmarshalingforstrings.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondefaultmarshalingforstrings.asp&lt;/A&gt;&lt;BR&gt;Objects: &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondefaultmarshalingforobjects.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondefaultmarshalingforobjects.asp&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[Author: Katie Blanch]&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Disclaimers:&lt;BR&gt;This posting is provided "AS IS" with no warranties, and confers no rights.&lt;BR&gt;Some of the information contained within this post may be in relation to beta software.&amp;nbsp;Any and all details are subject to change.&lt;/EM&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=442612" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/netcfteam/archive/tags/Author_3A00_+Katie+Blanch/default.aspx">Author: Katie Blanch</category></item><item><title>Interop Log File Information</title><link>http://blogs.msdn.com/netcfteam/archive/2005/07/24/442609.aspx</link><pubDate>Sun, 24 Jul 2005 10:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:442609</guid><dc:creator>NetCFTeam</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.msdn.com/netcfteam/comments/442609.aspx</comments><wfw:commentRss>http://blogs.msdn.com/netcfteam/commentrss.aspx?PostID=442609</wfw:commentRss><description>&lt;P class=style7&gt;&lt;FONT size=2&gt;&lt;STRONG&gt;&lt;EM&gt;This information will be included on MSDN soon...&lt;/EM&gt;&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/P&gt;
&lt;P class=style7&gt;&lt;FONT color=#000080 size=5&gt;&lt;STRONG&gt;How to: Create Log Files&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=style7&gt;&lt;FONT color=#808080 size=4&gt;&lt;STRONG&gt;Introduction&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=style7&gt;You can create log files with diagnostic information about interoperability, loading the application, and networking. You can enable logging by setting the registry keys. &lt;/P&gt;
&lt;P class=style7&gt;By default, log files are written to the same directory containing the application being diagnosed. However, you can you can specify a path and other options with registry keys as follows: &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Use an alternate path to write the log files. This requires privileged access to the secure registry. 
&lt;LI&gt;Include the application name in the log file name. 
&lt;LI&gt;Include the process ID in the log file name. &lt;/LI&gt;&lt;/UL&gt;
&lt;P class=style7&gt;A log file has the following parts: "netcf_" + (Application name) + (component) + (Process ID) + ".log".&lt;BR&gt;[component] corresponds to the type of logging information, either Interop, Loader, or Network. &lt;BR&gt;[Application name] is optional and [process ID] are optional and are specified with registry settings.&lt;/P&gt;
&lt;P class=style7&gt;For example, a Loader log file for "MyApp.exe" with the application name and process ID would be: netcf_MyApp_Loader_2066923010.log &lt;/P&gt;
&lt;P class=style7&gt;&lt;FONT color=#808080 size=4&gt;&lt;STRONG&gt;Procedures &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=style7&gt;&lt;STRONG&gt;To enable logging:&lt;/STRONG&gt; &lt;BR&gt;Set the Enabled key value 1: HKLM\Software\Microsoft\.NETCompactFramework\Diagnostics\Logging\Enabled &lt;BR&gt;This key value must be set to enable the three types of logging: Interop, Loader, and Networking. Note that the sub keys under Logging do not exist by default. &lt;BR&gt;You can turn off all logging by setting this value to zero. &lt;/P&gt;
&lt;P class=style7&gt;&lt;STRONG&gt;To specify a path for the log file (optional):&lt;/STRONG&gt; &lt;BR&gt;Set the Path key value to a string: HKLM\Security\.NETCompactFramework\Diagnostics\Logging\Path &lt;BR&gt;This key is only accessible by applications that can write to the secure registry. If a path is not specified, the log file is written to the same directory containing the application. &lt;/P&gt;
&lt;P class=style7&gt;&lt;STRONG&gt;To include the application in the name (optional):&lt;/STRONG&gt; &lt;BR&gt;Set the UseApp key value to 1: HKLM\Software\Microsoft\.NETCompactFramework\Diagnostics\Logging\UseApp &lt;BR&gt;This key is useful if you want to run multiple applications and get separate log files. If there are two applications writing log files to the same directory, the older log file will always get overwritten with the newer log file when the second application is run. This key can be used as a differentiator for the log file.&lt;/P&gt;
&lt;P class=style7&gt;&lt;STRONG&gt;To include the process ID in the name (optional):&lt;/STRONG&gt; &lt;BR&gt;Set the UsePid key value to 1: HKLM\Software\Microsoft\.NETCompactFramework\Diagnostics\Logging\UsePid &lt;BR&gt;This key is useful if you want to run the same application but have separate logs. This adds the process ID to the log file name, so that each run of the same application creates a new log file with a different name. &lt;/P&gt;
&lt;P class=style7&gt;&lt;STRONG&gt;To log events as they occur (optional):&lt;/STRONG&gt; &lt;BR&gt;Set the Flush key value to 1: HKLM\Software\Microsoft\.NETCompactFramework\Diagnostics\Logging\Flush &lt;BR&gt;This value causes the common language runtime to write log events to the log file as they occur instead of keeping them in the buffer and writing then when the buffer is full. Flushing negatively affects performance of the application and might modify timing of the application slightly since every piece of logging information is written out immediately, but it can be useful to diagnose problems related to application crashes or other errors where you might want to get the last few logs that resulted in the crash. If this key is not present or not set, then the default operation is to not flush.&lt;/P&gt;
&lt;P class=style7&gt;&lt;STRONG&gt;To enable Interop logging:&lt;/STRONG&gt; &lt;BR&gt;Set the Enabled key value to 1: HKLM\Software\Microsoft\.NETCompactFramework\Diagnostics\Logging\Interop\Enabled &lt;/P&gt;
&lt;P class=style7&gt;&lt;STRONG&gt;To enable Loader logging:&lt;/STRONG&gt; &lt;BR&gt;Set Enabled value to 1 to enable Loader logging, or set to 2 to enable Loader and GAC related logging: HKLM\Software\Microsoft\.NETCompactFramework\Diagnostics\Logging\Loader\Enabled &lt;/P&gt;
&lt;P class=style7&gt;&lt;STRONG&gt;To enable Networking logging: &lt;BR&gt;&lt;/STRONG&gt;Set the Enabled value to 1: HKLM\Software\Microsoft\.NETCompactFramework\Diagnostics\Logging\Networking\Enabled &lt;BR&gt;The networking log file is binary and cannot be read without the viewer, which is not currently available. &lt;/P&gt;
&lt;P class=style7&gt;&lt;STRONG&gt;&lt;FONT size=5&gt;&lt;FONT color=#000080&gt;Interop Log Files&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=style7&gt;The output for interop logging consists of the signatures of interop function calls as they occur at run time, as well as any error messages.&lt;/P&gt;
&lt;P class=style7&gt;&lt;FONT color=#808080 size=4&gt;&lt;STRONG&gt;Function Signatures&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=style7&gt;The signatures for both managed-to-native and native-to-managed calls are logged, and include the following types of calls: &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Platform invoke calls. 
&lt;LI&gt;COM vtable and Dispatch calls. 
&lt;LI&gt;Delegate callbacks. &lt;/LI&gt;&lt;/UL&gt;
&lt;P class=style7&gt;These function signatures can help you troubleshoot problems when calling or returning from an interop function call, such as when a parameter is not initialized as expected or when the program terminates unexpectedly.&lt;/P&gt;
&lt;P class=style7&gt;The output for a function signature entry consists of three lines for each interop call:&lt;/P&gt;
&lt;P class=style7&gt;Line 1) The first line represents flags identifying the type of function call made, and has one or more of the following elements:&lt;/P&gt;
&lt;P class=style7&gt;[pinvokeimpl] - A managed-to-native call that uses the System.Runtime.InteropServices.DllImportAttribute attribute.&amp;nbsp; &lt;BR&gt;[Ctor] - A constructor for an interop assembly class, generated by the Type Library Importer (Tlbimp.exe). &lt;BR&gt;[preservesig] - The managed and native functions are assumed to have the same signature, with no translation from HRESULT to exception enforced by the runtime. &lt;BR&gt;[delegate] - Indicates that the function is a native-to-managed delegate callback. The delegate acts as a function pointer in native code.&lt;/P&gt;
&lt;P class=style7&gt;Line 2) The second line of the interop log file represents the managed signature. For managed-to-native function calls, this line identifies the managed function that describes the PInvoke or com interface method. For native-to-managed function calls, this line identifies the managed function that is being called from native code. &lt;/P&gt;
&lt;P class=style7&gt;Line 3) The third line represents the native signature, as expected by the runtime. This line identifies data types for each parameter and provides information about how the managed object data is marshaled. The runtime assumes the correct types are specified by the System.Runtime.InteropServices.DllImportAttribute or in the COM interface signature definition. Failure to specify the correct types is a common error that can result in unexpected behavior because the function called is executed with incorrect parameter values.&amp;nbsp; &lt;BR&gt;Every type has a default marshaling type. Note that the marshaling behavior of a managed type can differ between COM calls and System.Runtime.InteropServices.DllImportAttribute calls or delegate callback calls. You can use the System.Runtime.InteropServices.MarshalAsAttribute attribute to specify a marshaling type other then the default. You must also use the ref keyword to identify parameters that are expected to be pointers in native code. &lt;/P&gt;
&lt;P class=style7&gt;The following example shows a signature entry for a PInvoke call:&amp;nbsp; &lt;/P&gt;
&lt;P class=style7&gt;1) [pinvokeimpl][preservesig] &lt;BR&gt;2) bool&amp;nbsp; PlatformDetector::SystemParametersInfo(uint , uint , System.Text.StringBuilder , uint ); &lt;BR&gt;3) BOOLEAN (I1_WINBOOL_VAL) SystemParametersInfo(unsigned int (U4_VAL) , unsigned int (U4_VAL) , WCHAR * (STRINGBUILDER_LPWSTR) , unsigned int (U4_VAL) );&lt;/P&gt;
&lt;P class=style7&gt;The following example shows a signature entry for a delegate callback. &lt;/P&gt;
&lt;P class=style7&gt;1) [preservesig][delegate] &lt;BR&gt;2) int&amp;nbsp; WndProc::Invoke(WndProc , IntPtr , uint , uint , int ); &lt;BR&gt;3) int (I4_VAL) (*)(INT_PTR (I_VAL) , unsigned int (U4_VAL) , unsigned int (U4_VAL) , int (I4_VAL) )&lt;/P&gt;
&lt;P class=style7&gt;The following example shows a signature entry for a native-to-managed COM function call, where the runtime returns a failure HRESULT in the event of a managed exception.&lt;/P&gt;
&lt;P class=style7&gt;1) [no flags] &lt;BR&gt;2) int&amp;nbsp; N2MDualComponentImp.IN2MDualInterface::GetInt(N2MDualComponentImp.IN2MDualInterface This); &lt;BR&gt;3) HRESULT GetInt(IN2MDualInterface *(INTF_VAL) this, [retval] int (I4_VAL) retval);&lt;/P&gt;
&lt;P class=style7&gt;&lt;FONT color=#808080 size=4&gt;&lt;STRONG&gt;Error Messages&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=style7&gt;You should search the interop log file for the keywords ‘ERROR’ and ‘WARNING’. Some situations can cause error messages to be recorded in the log file, which can be especially useful when investigating issues that involve interoperating with native components and DLLs for which the native source code is not available. You can use error messages to help diagnose the following issues:&lt;/P&gt;
&lt;P class=style7&gt;Native-to-managed function calls: &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Calling runtime COM interfaces. An HRESULT error can be returned to native code when a runtime-implemented COM interface function is called. There are several runtime-implemented interfaces, including IUnknown, IDispatch, IConnectionPointContainer, IEnumConnectionPoints, and IConnectionPoint, that native code can call into by using a managed object marshaled as a COM interface. When an error is returned to native code from a function call into one of these interfaces, the runtime prints out an appropriate error message giving the HRESULT and any additional relevant information. 
&lt;LI&gt;Native code expecting to use functionality that is unsupported, such as the CCW (COM callable wrapper) implementation of IDispatch::GetTypeInfo.&amp;nbsp; 
&lt;LI&gt;Unimplemented interfaces. Native code may receive an E_NOINTERFACE error from a CCW implementation of IUnknown::QueryInterface where it expects the managed COM object to have implemented an additional interface. In this case, the GUID of the unimplemented interface is also provided. &lt;/LI&gt;&lt;/UL&gt;
&lt;P class=style7&gt;Managed exceptions: &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Managed exceptions can occur inside the managed function call and cause it to return prematurely. When making a COM call, the runtime converts the exception into a failure HRESULT and returns this back to native code. However, for delegate callbacks and COM calls that do not expect HRESULT return values, there is no way to ensure native code is made aware of the error, and you may see unexpected behavior as a result. The interop log will contain an error message when an exception happens during a native-to-managed interop function call, helping you identify managed functions that need additional error-handling logic to work well with native code. The following factors can cause a managed exception. 
&lt;LI&gt;Using types in your COM interface definition or System.Runtime.InteropServices.DllImportAttribute signature that are not supported by the .NET Compact Framework will cause an exception to occur during the JIT compilation process.&amp;nbsp; There are often alternative options that are acceptable, such as an System.IntPtr . 
&lt;LI&gt;When either the actual object cannot be coerced to the type specified in the signature or the object data cannot be converted to the type requested, an exception is thrown at run time when the function is called.&amp;nbsp; This usually occurs when converting a native object into a managed object. 
&lt;LI&gt;Determining what causes an exception when creating a runtime callable wrapper (RCW) or a COM callable wrapper (CCW) is difficult. The interop log file can help determine the cause of these problems when a detailed error message is not provided with the managed exception. 
&lt;LI&gt;There are differences between .NET Compact Framework implementation of COM interoperability and that of the full .NET Framework. The following situations will cause a managed exception under the .NET Compact Framework: 
&lt;UL&gt;
&lt;LI&gt;Creating a CCW (COM callable wrapper) containing an interface without a specified GUID. 
&lt;LI&gt;Instantiating a class that inherits from an interop assembly class. 
&lt;LI&gt;Creating a CCW containing a nongeneric interface with a generic method. &lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Runtime callable wrappers (RCWs) are usually cleaned up upon finalization, but you can also use the System.Runtime.InteropServices.Marshal.ReleaseComObject(System.Object) or System.Runtime.InteropServices.Marshal.FinalReleaseComObject(System.Object) method to release the RCW associated with an object. If you are using these advanced options to manage the lifetime of your objects and you attempt to use the object after it has been freed to make a native COM call, an exception is thrown and the log file contains an error message about the cause of the exception. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;/P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;FONT face=Arial size=1&gt;&lt;FONT size=2&gt;[Author: Katie Blanch]&lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;Disclaimers:&lt;BR&gt;This posting is provided "AS IS" with no warranties, and confers no rights.&lt;BR&gt;Some of the information contained within this post may be in relation to beta software.&amp;nbsp; Any and all details are subject to change.&lt;/FONT&gt;&lt;FONT style="BACKGROUND-COLOR: #ffffff" size=2&gt;&lt;/FONT&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=442609" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/netcfteam/archive/tags/Author_3A00_+Katie+Blanch/default.aspx">Author: Katie Blanch</category></item></channel></rss>