コード例 #1
0
 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;
 }
コード例 #2
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;
        }