Esempio n. 1
0
        protected void Dispose(bool disposing)
        {
            //free up native memory
            IntPtr titleptr = (IntPtr)BitConverter.ToInt32(data, 4);

            if (titleptr != IntPtr.Zero)
            {
                MarshalEx.FreeHGlobal(titleptr);
                BitConverter.GetBytes((int)0).CopyTo(data, 4);
            }
            IntPtr textptr = (IntPtr)BitConverter.ToInt32(data, 8);

            if (textptr != IntPtr.Zero)
            {
                MarshalEx.FreeHGlobal(textptr);
                BitConverter.GetBytes((int)0).CopyTo(data, 8);
            }
            IntPtr soundptr = (IntPtr)BitConverter.ToInt32(data, 12);

            if (soundptr != IntPtr.Zero)
            {
                MarshalEx.FreeHGlobal(soundptr);
                BitConverter.GetBytes((int)0).CopyTo(data, 12);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Finds the first item after the specified index that matches the specified string.
        /// <para><b>New in v1.3</b></para>
        /// </summary>
        /// <param name="s">The <see cref="System.String"/> to search for.</param>
        /// <param name="startIndex">The zero-based index of the item before the first item to be searched. Set to -1 to search from the beginning of the control.</param>
        /// <returns>The zero-based index of the first item found; returns -1 if no match is found.</returns>
        public int FindStringExact(string s, int startIndex)
        {
            int    index   = -1;
            IntPtr pString = MarshalEx.StringToHGlobalUni(s);

            index = (int)Win32Window.SendMessage(this.Handle, (int)CB.FINDSTRINGEXACT, startIndex, pString);
            MarshalEx.FreeHGlobal(pString);
            return(index);
        }
Esempio n. 3
0
        /// <summary>
        /// This will the allocated memory from method <see cref="SecureStringToGlobalAllocUni"/>.
        /// </summary>
        /// <remarks>
        /// This method is located in the <see cref="Marshal"/> class in .NET Framework v2.0
        /// </remarks>
        public static void ZeroFreeGlobalAllocUni(IntPtr s)
        {
            // Demand Permission
            //new CryptographicPermission( CryptographicPermissionFlags.Decrypt ).Demand();
            //Win32Native.ZeroMemory( s, (uint)Win32Native.lstrlenW(s) * 2 );
            //int strLen = Win32Native.lstrlen(s);
            //Win32Native.ZeroMemory( s, (uint)Win32Native.lstrlen(s) * 2 );
            int strLen = Marshal.SizeOf(s);

            Win32Native.memset(s, 0, (uint)strLen * 2);
            MarshalEx.FreeHGlobal(s);
        }
Esempio n. 4
0
        /// <summary>
        /// Instruct the WebBrowser to jump to the indicated anchor.
        /// <para><b>New in v1.3</b></para>
        /// </summary>
        /// <param name="anchor">The name of the anchor to which the HTML control is to jump.</param>
        /// <remarks>If the anchor is already in the document, the jump occurs immediately.
        /// If the specified anchor is not in the document, the request will be remembered such that, if the anchor is added, the jump will occur as soon as the anchor is available.
        /// While there is a pending anchor, any navigation commands from the user, such as keyboard scrolling or using the scroll bar, aborts the pending anchor jump.</remarks>
        public void JumpToAnchor(string anchor)
        {
#if !DESIGN
            //allocate temporary native buffer
            IntPtr stringptr = MarshalEx.StringToHGlobalUni(anchor + '\0');

            //send message to native control adding to current text
            Win32Window.SendMessage(ChildHandle, (int)DTM.ANCHORW, 0, (int)stringptr);

            //free native memory
            MarshalEx.FreeHGlobal(stringptr);
#endif
        }
Esempio n. 5
0
        /// <summary>
        /// Loads the document at the specified URL into the <see cref="WebBrowser"/> control, replacing the previous document.
        /// </summary>
        /// <param name="url">The URL of the document to load.</param>
        public void Navigate(string url)
        {
#if !DESIGN
            //allocate temporary native buffer
            IntPtr stringptr = MarshalEx.StringToHGlobalUni(url + '\0');

            //send message to native control
            Win32Window.SendMessage(ChildHandle, (int)DTM.NAVIGATE, 0, (int)stringptr);

            //free native memory
            MarshalEx.FreeHGlobal(stringptr);
#endif
        }
Esempio n. 6
0
        /// <summary>
        /// Sets the symbols to use with the control on Smartphone.
        /// </summary>
        /// <param name="control">Control for which Symbol collection is to be used.</param>
        /// <param name="symbols">Collection of characters to be used as symbols.</param>
        public void SetSymbols(Control control, string symbols)
        {
            if (control is TextBox)
            {
                //get the handle to the child (native) control
                control.Capture = true;
                IntPtr hwnd = Win32Window.GetWindow(Win32Window.GetCapture(), GW.CHILD);
                control.Capture = false;

                IntPtr pSymbols = MarshalEx.StringToHGlobalUni(symbols);
                IntPtr result   = Win32Window.SendMessage(hwnd, EM_SETSYMBOLS, IntPtr.Zero, pSymbols.ToInt32());
                MarshalEx.FreeHGlobal(pSymbols);
            }
        }
Esempio n. 7
0
        internal static string GetErrorMessage(int ErrNo)
        {
            IntPtr pBuffer;
            int    nLen = Win32.Core.FormatMessage(Core.FormatMessageFlags.FromSystem | Core.FormatMessageFlags.AllocateBuffer, 0, ErrNo, 0, out pBuffer, 0, null);

            if (nLen == 0)              //Failed
            {
                return(string.Format("Error {0} (0x{0:X})", ErrNo));
            }
            string sMsg = MarshalEx.PtrToStringUni(pBuffer, 0, nLen);

            MarshalEx.FreeHGlobal(pBuffer);

            return(sMsg);
        }
Esempio n. 8
0
        /// <summary>
        /// Make a voice call to the specified number optionally prompting the user before dialling.
        /// </summary>
        /// <param name="destination">A valid phone number to be dialled.</param>
        /// <param name="prompt">If True user will be prompted before call is made, else call will be made without user intervention.</param>
        /// <param name="calledParty">A display name for the party being called.</param>
        /// <returns>True if successful else False</returns>
        public static bool MakeCall(string destination, bool prompt, string calledParty)
        {
            //setup structure for native call
            MakeCallInfo mci = new MakeCallInfo();

            mci.cbSize         = 24;
            mci.pszDestAddress = OpenNETCF.Runtime.InteropServices.MarshalEx.StringToHGlobalUni(destination);

            if (calledParty != null)
            {
                mci.pszCalledParty = OpenNETCF.Runtime.InteropServices.MarshalEx.StringToHGlobalUni(calledParty);
            }

            if (prompt)
            {
                mci.dwFlags = CallFlags.PromptBeforeCalling;
            }
            else
            {
                mci.dwFlags = CallFlags.Default;
            }

            //call native function
            int result = PhoneMakeCall(ref mci);

            //free strings
            if (mci.pszDestAddress != IntPtr.Zero)
            {
                MarshalEx.FreeHGlobal(mci.pszDestAddress);
            }

            if (mci.pszCalledParty != IntPtr.Zero)
            {
                MarshalEx.FreeHGlobal(mci.pszCalledParty);
            }

            //check return value
            if (result == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Reloads the document currently displayed in the WebBrowser control by checking the server for an updated version.
        /// </summary>
        public override void Refresh()
        {
            //only refresh if an address has been set
            if (m_url != null)
            {
#if !DESIGN
                //allocate temporary native buffer
                IntPtr stringptr = MarshalEx.StringToHGlobalUni(m_url + '\0');

                //send message to native control
                Win32Window.SendMessage(ChildHandle, (int)DTM.NAVIGATE, (int)NAVIGATEFLAG.REFRESH, (int)stringptr);

                //free native memory
                MarshalEx.FreeHGlobal(stringptr);
#endif
            }
        }
Esempio n. 10
0
        private FileVersionInfo(string fileName)
        {
            //get the filename sans path
            m_filename = System.IO.Path.GetFileName(fileName);

            int handle = 0;
            int len    = 0;

            //get size of version info
            len = GetFileVersionInfoSize(fileName, ref handle);

            if (len > 0)
            {
                //allocate buffer
                IntPtr buffer = MarshalEx.AllocHGlobal(len);
                //get version information
                if (GetFileVersionInfo(fileName, handle, len, buffer))
                {
                    IntPtr fixedbuffer = IntPtr.Zero;
                    int    fixedlen    = 0;
                    //get language independant version info
                    //this is a pointer within the main buffer so don't free it
                    if (VerQueryValue(buffer, "\\", ref fixedbuffer, ref fixedlen))
                    {
                        //allocate managed memory
                        m_fixedversioninfo = new byte[fixedlen];
                        //copy to managed memory
                        Marshal.Copy(fixedbuffer, m_fixedversioninfo, 0, fixedlen);
                    }
                    else
                    {
                        throw new WinAPIException("Error retrieving language independant version");
                    }
                }
                else
                {
                    throw new WinAPIException("Error retrieving FileVersionInformation");
                }

                //free native buffer
                MarshalEx.FreeHGlobal(buffer);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Adds text to the WebBrowser control.
        /// </summary>
        /// <param name="text">Text to be added.</param>
        /// <param name="plain">If TRUE text is treated as plain text, else treated as HTML Source.</param>
        public void AddText(string text, bool plain)
        {
#if !DESIGN
            //allocate temporary native buffer
            IntPtr stringptr = MarshalEx.StringToHGlobalUni(text + '\0');

            int iplain = 0;

            if (plain)
            {
                iplain = -1;
            }

            //send message to native control adding to current text
            Win32Window.SendMessage(ChildHandle, (int)DTM.ADDTEXTW, iplain, (int)stringptr);

            //free native memory
            MarshalEx.FreeHGlobal(stringptr);
#endif
        }
Esempio n. 12
0
        protected void Dispose(bool disposing)
        {
            //free strings
            IntPtr appptr = (IntPtr)BitConverter.ToInt32(data, 12);

            if (appptr != IntPtr.Zero)
            {
                MarshalEx.FreeHGlobal(appptr);
                BitConverter.GetBytes(0).CopyTo(data, 12);
            }
            IntPtr argptr = (IntPtr)BitConverter.ToInt32(data, 16);

            //if native string already allocated
            if (argptr != IntPtr.Zero)
            {
                //free previous value
                MarshalEx.FreeHGlobal(argptr);
                BitConverter.GetBytes(0).CopyTo(data, 16);
            }
        }
Esempio n. 13
0
        //called when a change occurs in the bound collection
        private void ComboBoxEx_ListChanged(object sender, ListChangedEventArgs e)
        {
            if (m_updatable)
            {
                if (e.ListChangedType == ListChangedType.ItemChanged)
                {
                    //update the item

                    //delete old item
                    Win32Window.SendMessage(this.Handle, CB_DELETESTRING, e.NewIndex, 0);
                    //get display text for new item
                    string newval = this.GetItemText(this.Items[e.NewIndex]);
                    //marshal to native memory
                    IntPtr pString = MarshalEx.StringToHGlobalUni(newval);
                    //send message to native control
                    Win32Window.SendMessage(this.Handle, CB_INSERTSTRING, e.NewIndex, pString);
                    //free native memory
                    MarshalEx.FreeHGlobal(pString);
                }
            }
        }
Esempio n. 14
0
        private void Show()
        {
            m_data.pszHTML    = MarshalEx.StringToHGlobalUni(mText);
            m_data.pszTitle   = MarshalEx.StringToHGlobalUni(mCaption);
            m_data.hicon      = mIcon;
            m_data.csDuration = mDuration;

            if (mDuration == 0)
            {
                m_data.npPriority = SHNP.ICONIC;
            }
            else
            {
                m_data.npPriority = SHNP.INFORM;
            }

            if (mCritical)
            {
                m_data.grfFlags |= SHNF.CRITICAL;
            }
            else
            {
                m_data.grfFlags ^= (m_data.grfFlags & SHNF.CRITICAL);
            }

            int hresult = SHNotificationAdd(ref m_data);

            if (m_data.pszTitle != IntPtr.Zero)
            {
                MarshalEx.FreeHGlobal(m_data.pszTitle);
                m_data.pszTitle = IntPtr.Zero;
            }
            if (m_data.pszHTML != IntPtr.Zero)
            {
                MarshalEx.FreeHGlobal(m_data.pszHTML);
                m_data.pszHTML = IntPtr.Zero;
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Get an array of available network adapters
        /// </summary>
        /// <returns>aArray of AdapterInfo classes</returns>
        public static AdapterInfo[] GetAdaptersInfo()
        {
            ArrayList adapters = new ArrayList();

            int cb  = 0;
            int ret = GetAdaptersInfoCE(IntPtr.Zero, ref cb);

            IntPtr pInfo = MarshalEx.AllocHGlobal(cb);             //LPTR

            ret = GetAdaptersInfoCE(pInfo, ref cb);
            if (ret == 0)
            {
                AdapterInfo info = new AdapterInfo(pInfo, 0);
                while (info != null)
                {
                    adapters.Add(info);
                    info = info.Next;
                }
            }
            MarshalEx.FreeHGlobal(pInfo);

            return((AdapterInfo[])adapters.ToArray(Type.GetType("OpenNETCF.Net.AdapterInfo")));
        }
Esempio n. 16
0
        /// <summary>
        /// Retrieves notification information associated with a handle.
        /// </summary>
        /// <param name="handle">Handle to the user notification to retrieve.</param>
        /// <returns>The requested UserNotification.</returns>
        public static UserNotificationInfoHeader GetUserNotification(int handle)
        {
            //buffer size
            int size = 0;

            //first query for buffer size required
            CeGetUserNotification(handle, 0, ref size, IntPtr.Zero);

            //create a marshallable buffer
            IntPtr buffer = MarshalEx.AllocHGlobal(size);

            //call native getter
            if (!CeGetUserNotification(handle, (uint)size, ref size, buffer))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "Error getting UserNotification");
            }

            UserNotificationInfoHeader nih = UserNotificationInfoHeader.FromPtr(buffer);

            //free native memory
            MarshalEx.FreeHGlobal(buffer);

            return(nih);
        }
Esempio n. 17
0
 public void Dispose()
 {
     MarshalEx.FreeHGlobal(m_lpData);
     MarshalEx.FreeHGlobal(m_lpHeader);
 }