private IntPtr AllocMsaaMenuInfo()
        {
            this.FreeMsaaMenuInfo();
            this.msaaMenuInfoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MsaaMenuInfoWithId)));
            int size = IntPtr.Size;
            MsaaMenuInfoWithId structure = new MsaaMenuInfoWithId(this.data.caption, this.uniqueID);

            Marshal.StructureToPtr(structure, this.msaaMenuInfoPtr, false);
            return(this.msaaMenuInfoPtr);
        }
        internal static MenuItem GetMenuItemFromItemData(IntPtr itemData)
        {
            uint uniqueID = (uint)((long)itemData);

            if (uniqueID == 0)
            {
                return(null);
            }
            if (IntPtr.Size == 4)
            {
                if (uniqueID < 0xc0000000)
                {
                    MsaaMenuInfoWithId id = (MsaaMenuInfoWithId)Marshal.PtrToStructure(itemData, typeof(MsaaMenuInfoWithId));
                    uniqueID = id.uniqueID;
                }
            }
            else
            {
                MsaaMenuInfoWithId id2 = (MsaaMenuInfoWithId)Marshal.PtrToStructure(itemData, typeof(MsaaMenuInfoWithId));
                uniqueID = id2.uniqueID;
            }
            return(GetMenuItemFromUniqueID(uniqueID));
        }
 private IntPtr AllocMsaaMenuInfo()
 {
     this.FreeMsaaMenuInfo();
     this.msaaMenuInfoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MsaaMenuInfoWithId)));
     int size = IntPtr.Size;
     MsaaMenuInfoWithId structure = new MsaaMenuInfoWithId(this.data.caption, this.uniqueID);
     Marshal.StructureToPtr(structure, this.msaaMenuInfoPtr, false);
     return this.msaaMenuInfoPtr;
 }
Exemplo n.º 4
0
        // Creates an MSAAMENUINFO structure (in the unmanaged heap) based on the current state
        // of this MenuItem object. Address of this structure is cached in the object so we can
        // free it later on using FreeMsaaMenuInfo(). If structure has already been allocated,
        // it is destroyed and a new one created.
        private IntPtr AllocMsaaMenuInfo() {
            FreeMsaaMenuInfo();
            msaaMenuInfoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MsaaMenuInfoWithId)));

            // To check it's 32-bit OS or 64-bit OS.
            if (IntPtr.Size == 4) {
                // We only check this on Win32, irrelevant on Win64 (see CreateMenuItemInfo)
                Debug.Assert(((uint) (ulong) msaaMenuInfoPtr) < firstUniqueID); // ...check for incursion into menu item ID range (unlikely!)
            }

            MsaaMenuInfoWithId msaaMenuInfoStruct = new MsaaMenuInfoWithId(data.caption, uniqueID);
            Marshal.StructureToPtr(msaaMenuInfoStruct, msaaMenuInfoPtr, false);
            Debug.Assert(msaaMenuInfoPtr != IntPtr.Zero);
            return msaaMenuInfoPtr;
        }