System.Runtime.InteropServices.GCHandle.AddrOfPinnedObject C# (CSharp) Method

AddrOfPinnedObject() private method

private AddrOfPinnedObject ( ) : IntPtr
return System.IntPtr
        public IntPtr AddrOfPinnedObject()
        {
            // Check if the handle was not a pinned handle.
            if (!IsPinned())
            {
                // Check if the handle was never initialized for was freed.
                if (m_handle == IntPtr.Zero)
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_HandleIsNotInitialized"));

                // You can only get the address of pinned handles.
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_HandleIsNotPinned"));
            }

            // Get the address.
            return InternalAddrOfPinnedObject(GetHandleValue());
        }

Usage Example

コード例 #1
0
        private static void EnsureFontLoaded()
        {
            if (_FontAwesome == null)
            {
                _PrivateFontCollection = new PrivateFontCollection();

                byte[] fontAwesomeBuffer = BarFunctions.LoadFont("SystemImages.FontAwesome.ttf");
                _FontAwesomeHandle = GCHandle.Alloc(fontAwesomeBuffer, GCHandleType.Pinned);
                _PrivateFontCollection.AddMemoryFont(_FontAwesomeHandle.AddrOfPinnedObject(), fontAwesomeBuffer.Length);
                uint rsxCnt = 1;
                _FontAwesomePointer = AddFontMemResourceEx(_FontAwesomeHandle.AddrOfPinnedObject(),
                                                     (uint)fontAwesomeBuffer.Length, IntPtr.Zero, ref rsxCnt);
                using (FontFamily ff = _PrivateFontCollection.Families[0])
                {
                    if (ff.IsStyleAvailable(FontStyle.Regular))
                    {
                        _FontAwesome = new Font(ff, _FontAwesomeDefaultSize, FontStyle.Regular, GraphicsUnit.Point);
                        _FontAwesomeCache.Add(_FontAwesomeDefaultSize, _FontAwesome);
                    }
                    else
                    {
                        // Error use default font...
                        _FontAwesome = SystemInformation.MenuFont;
                    }
                }
            }
        }
All Usage Examples Of System.Runtime.InteropServices.GCHandle::AddrOfPinnedObject