Exemplo n.º 1
0
        private static unsafe void SetText(IntPtr pCmdTextInt, string text)
        {
            OLECMDTEXT *pText = (OLECMDTEXT *)pCmdTextInt;

            // If, for some reason, we don't get passed an array, we should just bail
            if (pText->cwBuf == 0)
            {
                return;
            }

            fixed(char *pinnedText = text)
            {
                char *src  = pinnedText;
                char *dest = (char *)(&pText->rgwz);

                // Don't copy too much, and make sure to reserve space for the terminator
                int length = Math.Min(text.Length, (int)pText->cwBuf - 1);

                for (int i = 0; i < length; i++)
                {
                    *dest++ = *src++;
                }

                // Add terminating NUL
                *dest = '\0';

                pText->cwActual = (uint)length;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OleCommandText"/> class from the specified pointer.
        /// </summary>
        /// <param name="oleCmdText">A pointer to the <see cref="OLECMDTEXT"/> structure in unmanaged memory.</param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="oleCmdText"/> is <see cref="IntPtr.Zero"/>.
        /// </exception>
        private unsafe OleCommandText(OLECMDTEXT *oleCmdText)
        {
            if (oleCmdText == null)
            {
                throw new ArgumentNullException(nameof(oleCmdText));
            }

            _oleCmdText = oleCmdText;
        }
Exemplo n.º 3
0
        private static unsafe string GetText(IntPtr pCmdTextInt)
        {
            if (pCmdTextInt == IntPtr.Zero)
            {
                return(string.Empty);
            }

            OLECMDTEXT *pText = (OLECMDTEXT *)pCmdTextInt;

            // Punt early if there is no text in the structure.
            if (pText->cwActual == 0)
            {
                return(string.Empty);
            }

            return(new string((char *)&pText->rgwz, 0, (int)pText->cwActual));
        }
 public HRESULT QueryStatus([NativeTypeName("const GUID *")] Guid *pguidCmdGroup, [NativeTypeName("ULONG")] uint cCmds, [NativeTypeName("OLECMD []")] OLECMD *prgCmds, OLECMDTEXT *pCmdText)
 {
     return(((delegate * unmanaged <IOleCommandTarget *, Guid *, uint, OLECMD *, OLECMDTEXT *, int>)(lpVtbl[3]))((IOleCommandTarget *)Unsafe.AsPointer(ref this), pguidCmdGroup, cCmds, prgCmds, pCmdText));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OleCommandText"/> class from the specified pointer.
 /// </summary>
 /// <param name="oleCmdText">A pointer to the <see cref="OLECMDTEXT"/> structure in unmanaged memory.</param>
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="oleCmdText"/> is <see cref="IntPtr.Zero"/>.
 /// </exception>
 private unsafe OleCommandText(OLECMDTEXT* oleCmdText)
 {
     Contract.Requires<ArgumentNullException>(oleCmdText != null, "oleCmdText");
     _oleCmdText = oleCmdText;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OleCommandText"/> class from the specified pointer.
 /// </summary>
 /// <param name="oleCmdText">A pointer to the <see cref="OLECMDTEXT"/> structure in unmanaged memory.</param>
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="oleCmdText"/> is <see cref="IntPtr.Zero"/>.
 /// </exception>
 private unsafe OleCommandText(OLECMDTEXT *oleCmdText)
 {
     Contract.Requires <ArgumentNullException>(oleCmdText != null, "oleCmdText");
     _oleCmdText = oleCmdText;
 }