Exemplo n.º 1
0
        public static void SetCommandText(IntPtr pCmdTextInt, string text)
        {
            if (text != null)
            {
                OLECMDTEXT olecmdtext = (OLECMDTEXT)Marshal.PtrToStructure(pCmdTextInt, typeof(OLECMDTEXT));
                if ((olecmdtext.cmdtextf & (uint)OLECMDTEXTF.OLECMDTEXTF_NAME) == 0)
                {
                    return;
                }

                char[] source       = text.ToCharArray();
                IntPtr bufferOffset = Marshal.OffsetOf(typeof(OLECMDTEXT), "rgwz");
                IntPtr lengthOffset = Marshal.OffsetOf(typeof(OLECMDTEXT), "cwActual");
                int    length       = Math.Min(((int)olecmdtext.cwBuf) - 1, source.Length);

                // copy the new text
                long bufferAddress = (long)pCmdTextInt + (long)bufferOffset;
                Marshal.Copy(source, 0, (IntPtr)bufferAddress, length);

                // null terminator
                Marshal.WriteInt16(pCmdTextInt, (int)bufferOffset + (length * 2), 0);

                // length including null terminator
                Marshal.WriteInt32(pCmdTextInt, (int)lengthOffset, length + 1);
            }
        }
Exemplo n.º 2
0
            public static IntPtr OffsetOf <T>(string fieldName)
            {
#if NET45
                return(SystemMarshal.OffsetOf(typeof(T), fieldName));
#else
                return(SystemMarshal.OffsetOf <T>(fieldName));
#endif
            }
Exemplo n.º 3
0
        private static string GetCommandText(IntPtr structPtr)
        {
            if (structPtr == IntPtr.Zero)
            {
                return(string.Empty);
            }

            OLECMDTEXT olecmdtext = (OLECMDTEXT)Marshal.PtrToStructure(structPtr, typeof(OLECMDTEXT));

            if (olecmdtext.cwActual == 0)
            {
                return(string.Empty);
            }

            IntPtr offset = Marshal.OffsetOf(typeof(OLECMDTEXT), "rgwz");
            IntPtr ptr    = (IntPtr)((long)structPtr + (long)offset);

            return(Marshal.PtrToStringUni(ptr, (int)olecmdtext.cwActual - 1));
        }
Exemplo n.º 4
0
 public static IntPtr OffsetOf <T>(string fieldName)
 {
     return(SystemMarshal.OffsetOf <T>(fieldName));
 }