C# (CSharp) Класс System.Runtime.InteropServices. HandleRef Code Examples

C# (CSharp) System.Runtime.InteropServices.HandleRef - 30 примеров найдено. Это лучшие примеры C# (CSharp) кода для класса System.Runtime.InteropServices.HandleRef, полученные из open source проектов. Вы можете ставить оценку каждому примеру, чтобы помочь нам улучшить качество примеров.
Пример #1
0
 // This static method is required because legacy OSes do not support
 // SetWindowLongPtr
 internal static IntPtr SetWindowLongPtr(HandleRef hWnd, int nIndex, IntPtr dwNewLong)
 {
     if (IntPtr.Size == 8)
         return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
     else
         return new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32()));
 }
Пример #2
0
    internal CompilationMutex(String name, String comment) {

#if !FEATURE_PAL // No unmanaged aspnet_isapi mutex in Coriolis

        // Attempt to get the mutex string from the registry (VSWhidbey 415795)
        string mutexRandomName = (string) Misc.GetAspNetRegValue("CompilationMutexName",
            null /*valueName*/, null /*defaultValue*/);

        if (mutexRandomName != null) {
            // If we were able to use the registry value, use it.  Also, we need to prepend "Global\"
            // to the mutex name, to make sure it can be shared between a terminal server session
            // and IIS (VSWhidbey 307523).
            _name += @"Global\" + name + "-" + mutexRandomName;
        }
        else {
            // If we couldn't get the reg value, don't use it, and prepend "Local\" to the mutex
            // name to make it local to the session (and hence prevent hijacking)
            _name += @"Local\" + name;
        }

        _comment = comment;

        Debug.Trace("Mutex", "Creating Mutex " + MutexDebugName);

        _mutexHandle = new HandleRef(this, UnsafeNativeMethods.InstrumentedMutexCreate(_name));

        if (_mutexHandle.Handle == IntPtr.Zero) {
            Debug.Trace("Mutex", "Failed to create Mutex " + MutexDebugName);

            throw new InvalidOperationException(SR.GetString(SR.CompilationMutex_Create));
        }

        Debug.Trace("Mutex", "Successfully created Mutex " + MutexDebugName);
#endif // !FEATURE_PAL
    }
Пример #3
0
 public static IntPtr SetWindowLong(HandleRef hwnd, Win32Native.WindowLongType index, IntPtr wndProcPtr)
 {
     if (IntPtr.Size == 4)
     return Win32Native.SetWindowLong32(hwnd, index, wndProcPtr);
       else
     return Win32Native.SetWindowLongPtr64(hwnd, index, wndProcPtr);
 }
Пример #4
0
        public Profile(string path)
        {
            Handle = new HandleRef (this, NativeMethods.CmsOpenProfileFromFile (path, "r"));

            if (Handle.Handle == IntPtr.Zero)
                throw new CmsException ("Error opening ICC profile in file " + path);
        }
 internal static void Unregister(HandleRef unmanaged)
 {
     lock (Instance)
     {
         Instance.UnregisterImpl(unmanaged.Handle);
     }
 }
Пример #6
0
 internal static extern void SnapshotManager_Open(
     HandleRef self,
      /* from(DataSource_t) */ Types.DataSource data_source,
      /* from(char const *) */ string file_name,
      /* from(SnapshotConflictPolicy_t) */ Types.SnapshotConflictPolicy conflict_policy,
      /* from(SnapshotManager_OpenCallback_t) */ OpenCallback callback,
      /* from(void *) */ IntPtr callback_arg);
 protected override HandleRef BuildWindowCore(HandleRef hwndParent)
 {
     DestroyHost();
     _host = new WinFormsAvaloniaControlHost {Content = _content};
     UnmanagedMethods.SetParent(_host.Handle, hwndParent.Handle);
     return new HandleRef(this, _host.Handle);
 }
        /// Drawing methods.

        /// <devdoc>
        /// </devdoc>
        public void DrawPie(WindowsPen pen, Rectangle bounds, float startAngle, float sweepAngle) 
        {
            HandleRef hdc = new HandleRef( this.dc, this.dc.Hdc);

            if( pen != null )
            {
                // 1. Select the pen in the DC
                IntUnsafeNativeMethods.SelectObject(hdc, new HandleRef(pen, pen.HPen));
            }

            // 2. call the functions
            // we first draw a path that goes : 
            // from center of pie, draw arc (this draw the line to the beginning of the arc
            // then, draw the closing line.
            // paint the path with the pen
            int sideLength = Math.Min(bounds.Width, bounds.Height);
            Point p = new Point(bounds.X+sideLength/2, bounds.Y+sideLength/2);
            int radius = sideLength/2;
            IntUnsafeNativeMethods.BeginPath(hdc);
            IntUnsafeNativeMethods.MoveToEx(hdc, p.X, p.Y, null);
            IntUnsafeNativeMethods.AngleArc(hdc, p.X, p.Y, radius, startAngle, sweepAngle);
            IntUnsafeNativeMethods.LineTo(hdc, p.X, p.Y);
            IntUnsafeNativeMethods.EndPath(hdc);
            IntUnsafeNativeMethods.StrokePath(hdc);
        }
Пример #9
0
	public static extern int SHGetFolderLocation(
		HandleRef hwndOwner,
		int nFolder,
		IntPtr hToken,
		int dwReserved,
		out IntPtr ppidl
		);
Пример #10
0
        public RazorBitmapFormAntiparents()
        {
            InitializeComponent();

            this.SetStyle(ControlStyles.DoubleBuffer, false);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.Opaque, true);

            SimpleParticlesWorld.Size = this.ClientSize;

            this.task = Task.Factory.StartNew(() =>
                {
                    using (Graphics graphics = this.CreateGraphics())
                    {
                        IntPtr hdc = IntPtr.Zero;
                        try
                        {
                            hdc = graphics.GetHdc();
                            HandleRef handleRef = new HandleRef(graphics, hdc);

                            while (!this.IsTerminate)
                            {
                                this.commonStopwatch.Restart();

                                this.updateStopwatch.Restart();
                                SimpleParticlesWorld.Update();
                                this.updateTime = this.updateStopwatch.ElapsedMilliseconds;

                                this.renderStopwatch.Restart();
                                Array.Clear(this.array, 0, this.array.Length);
                                SimpleParticle particle;
                                int pointBase;
                                for (int i = SimpleParticlesWorld.Particles.Count - 1; i >= 0; --i)
                                {
                                    particle = SimpleParticlesWorld.Particles[i];
                                    //foreach (SimpleParticle particle in SimpleParticlesWorld.Particles)
                                    //{
                                    pointBase = (this.size.Height - (int)particle.y) * this.size.Width + (int)particle.x;
                                    if (0 <= pointBase && pointBase < this.array.Length)
                                    {
                                        this.array[pointBase] = particle.c;
                                    }
                                }
                                SetDIBitsToDevice(handleRef, 0, 0, this.size.Width, this.size.Height, 0, 0, 0, this.size.Height, ref this.array[0], ref this.bitmapInfo, 0);
                                this.renderTime = this.renderStopwatch.ElapsedMilliseconds;

                                this.commonTime = this.commonStopwatch.ElapsedMilliseconds;
                            }
                        }
                        finally
                        {
                            if (hdc != IntPtr.Zero)
                            {
                                graphics.ReleaseHdc(hdc);
                            }
                        }
                    }
                });
        }
Пример #11
0
 /// <summary>
 /// コントロール作成
 /// </summary>
 /// <param name="hwndParent">親ウィンドウ</param>
 /// <returns>
 /// 作成されたコントロールの HandleRef 
 /// </returns>
 protected override HandleRef BuildWindowCore(HandleRef hwndParent)
 {
     Dispatcher.ShutdownStarted += DispatcherOnShutdownStarted;
     return new HandleRef(this,
         _wnd.CreateWindow(hwndParent.Handle)
         );
 }
Пример #12
0
        //private static readonly int CDINDEX_ID_LEN = 28;
        //private static readonly int ID_LEN = 36;
        public Client()
        {
            handle = new HandleRef(this, mb_New());
            UseUtf8 = true;

            AutoSetProxy();
        }
        protected override HandleRef BuildWindowCore(HandleRef hwndParent)
        {
            // Let our base class create the standard window.  We will simply
            // use it as the parent of our HwndSource.
            // HandleRef hwndChild = base.BuildWindowCore(hwndParent);

            HwndSourceParameters? optCreationParameters = CreationParameters;

            if (_thread != null)
            {
                // Asynchronously create the HwndSource on the worker thread.
                _thread.Dispatcher.BeginInvoke((Action)delegate
                {
                    _hwndSource = CreateHwndSource(optCreationParameters, hwndParent.Handle);
                });
            }
            else
            {
                // Synchronously create the HwndSource on the UI thread.
                _hwndSource = CreateHwndSource(optCreationParameters, hwndParent.Handle);
            }

            UpdateRootVisual(Source);

            return new HandleRef(this,_hwndSource.Handle);
        }
Пример #14
0
        protected override HandleRef BuildWindowCore(HandleRef hwndParent)
        {
            HwndListBox = IntPtr.Zero;
            _hwndHost = IntPtr.Zero;

            _hwndHost = CreateWindowEx(0, "static", "",
                WsChild | WsVisible,
                0, 0,
                _hostHeight, _hostWidth,
                hwndParent.Handle,
                (IntPtr) HostId,
                IntPtr.Zero,
                0);

            HwndListBox = CreateWindowEx(0, "listbox", "",
                WsChild | WsVisible | LbsNotify
                | WsVscroll | WsBorder,
                0, 0,
                _hostHeight, _hostWidth,
                _hwndHost,
                (IntPtr) ListboxId,
                IntPtr.Zero,
                0);

            return new HandleRef(this, _hwndHost);
        }
 internal static extern void RealTimeMultiplayerManager_SendUnreliableMessage(
     HandleRef self,
  /* from(RealTimeRoom_t) */IntPtr room,
  /* from(MultiplayerParticipant_t const *) */IntPtr[] participants,
  /* from(size_t) */UIntPtr participants_size,
  /* from(uint8_t const *) */byte[] data,
  /* from(size_t) */UIntPtr data_size);
Пример #16
0
        public Font( Type font )
        {
            IntPtr fontHandle;

            switch( font )
            {
                case Type.Small:
                    fontHandle = GDImport.gdFontGetSmall();
                    break;
                case Type.Large:
                    fontHandle = GDImport.gdFontGetLarge();
                    break;
                case Type.MediumBold:
                    fontHandle = GDImport.gdFontGetMediumBold();
                    break;
                case Type.Giant:
                    fontHandle = GDImport.gdFontGetGiant();
                    break;
                case Type.Tiny:
                    fontHandle = GDImport.gdFontGetTiny();
                    break;
                default:
                    throw new ApplicationException( font + " is no valid font." );
            }

            if( fontHandle == IntPtr.Zero )
                throw new ApplicationException( "The font retrieval failed." );

            this.handle = new HandleRef( this, fontHandle );
        }
        public static void SendStopMessage(this Process process)
        {
            Debug.Assert(process != null);

            try
            {
                if (!process.HasExited)
                {
                    var processId = process.Id;

                    for (var ptr = NativeMethods.GetTopWindow(IntPtr.Zero);
                        ptr != IntPtr.Zero;
                        ptr = NativeMethods.GetWindow(ptr, 2))
                    {
                        uint num;
                        NativeMethods.GetWindowThreadProcessId(ptr, out num);
                        if (processId == num)
                        {
                            var hWnd = new HandleRef(null, ptr);
                            NativeMethods.PostMessage(hWnd, 0x12, IntPtr.Zero, IntPtr.Zero);
                            return;
                        }
                    }
                }
            }
            catch (InvalidOperationException) { }
            catch (ArgumentException) { }
        }
 internal static void Register(HandleRef unmanaged)
 {
     lock (Instance)
     {
         Instance.RegisterImpl(unmanaged);
     }
 }
Пример #19
0
        protected override HandleRef BuildWindowCore(HandleRef hwndParent)
        {
            m_msgMng.m_hwndGLParent = IntPtr.Zero;

            m_msgMng.m_hwndGLParent = CreateWindowEx(
                0, "static", "",
                WS_CHILD | WS_VISIBLE,
                0, 0,
                m_hostWidth, m_hostHeight,
                hwndParent.Handle,
                (IntPtr)HOST_ID,
                IntPtr.Zero,
                0);

            string strRunMode;

            if (MainWindow.s_pW.m_isDebug)
            {
                strRunMode = "true";
            }
            else
            {
                strRunMode = "false";
            }

            m_process = System.Diagnostics.Process.Start(
                MainWindow.s_pW.m_pathGlApp,
                    m_hostWidth.ToString() + " " +
                    m_hostHeight.ToString() + " " +
                    m_msgMng.m_hwndGLParent.ToString() + " " +
                    strRunMode);

            return new HandleRef(this, m_msgMng.m_hwndGLParent);
        }
Пример #20
0
 internal static extern void LeaderboardManager_FetchScorePage(
     HandleRef self,
      /* from(DataSource_t) */ Types.DataSource data_source,
      /* from(ScorePage_ScorePageToken_t) */ IntPtr token,
      /* from(uint32_t) */ uint max_results,
      /* from(LeaderboardManager_FetchScorePageCallback_t) */ FetchScorePageCallback callback,
      /* from(void *) */ IntPtr callback_arg);
Пример #21
0
 //�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡξ����ȡ����
 public static IntPtr GetDesktopHandle(DesktopLayer layer,Form targetForm)
 {
     //hWnd = new HandleRef();
     HandleRef hWnd;
     IntPtr m_ptDesktop = new IntPtr();
     switch (layer)
     {
         case DesktopLayer.Progman:
             m_ptDesktop = EmbedFormApi.FindWindow(m_stProgman, null);//��һ������
             break;
         case DesktopLayer.SHELLDLL:
             m_ptDesktop = EmbedFormApi.FindWindow(m_stProgman, null);//��һ������
             hWnd = new HandleRef(targetForm, m_ptDesktop);
             m_ptDesktop = EmbedFormApi.GetWindow(hWnd, GW_CHILD);//��2������
             break;
         case DesktopLayer.FolderView:
             m_ptDesktop = EmbedFormApi.FindWindow(m_stProgman, null);//��һ������
             hWnd = new HandleRef(targetForm, m_ptDesktop);
             m_ptDesktop = EmbedFormApi.GetWindow(hWnd, GW_CHILD);//��2������
             hWnd = new HandleRef(targetForm, m_ptDesktop);
             m_ptDesktop = EmbedFormApi.GetWindow(hWnd, GW_CHILD);//��3������
             break;
     }
     return m_ptDesktop;
 }
Пример #22
0
 public static IntPtr GetWindowLong(HandleRef hWnd, Win32Native.WindowLongType index)
 {
     if (IntPtr.Size == 4)
     return Win32Native.GetWindowLong32(hWnd, index);
       else
     return Win32Native.GetWindowLong64(hWnd, index);
 }
 protected void HideCheckBox(TV_ITEM tv_item)
 {
     if (tv_item.ItemHandle != IntPtr.Zero)
     {
         // get TreeNode-object, that corresponds to TV_ITEM-object             
         TreeNode currentTN = TreeNode.FromHandle(this, tv_item.ItemHandle);
         HiddenCheckBoxTreeNode hiddenCheckBoxTreeNode = currentTN as HiddenCheckBoxTreeNode;
         // check if it's HiddenCheckBoxTreeNode and             
         // if its checkbox already has been hidden               
         if (hiddenCheckBoxTreeNode != null)
         {
             HandleRef treeHandleRef = new HandleRef(this, Handle);
             // check if checkbox already has been hidden                 
             TV_ITEM currentTvItem = new TV_ITEM();
             currentTvItem.ItemHandle = tv_item.ItemHandle;
             currentTvItem.StateMask = TVIS_STATEIMAGEMASK;
             currentTvItem.State = 0;
             IntPtr res = SendMessage(treeHandleRef, TVM_GETITEM, 0, ref currentTvItem);
             bool needToHide = res.ToInt32() > 0 && currentTvItem.State != 0;
             if (needToHide)
             {
                 // specify attributes to update                     
                 TV_ITEM updatedTvItem = new TV_ITEM();
                 updatedTvItem.ItemHandle = tv_item.ItemHandle;
                 updatedTvItem.Mask = TVIF_STATE;
                 updatedTvItem.StateMask = TVIS_STATEIMAGEMASK;
                 updatedTvItem.State = 0;
                 // send TVM_SETITEM message                     
                 SendMessage(treeHandleRef, TVM_SETITEM, 0, ref updatedTvItem);
             }
         }
     }
 }
 internal static extern void TurnBasedMultiplayerManager_ShowPlayerSelectUI(
     HandleRef self,
      /* from(uint32_t) */ uint minimum_players,
      /* from(uint32_t) */ uint maximum_players,
     [MarshalAs(UnmanagedType.I1)] /* from(bool) */ bool allow_automatch,
      /* from(TurnBasedMultiplayerManager_PlayerSelectUICallback_t) */ PlayerSelectUICallback callback,
      /* from(void *) */ IntPtr callback_arg);
Пример #25
0
 protected ChipmunkObject(IntPtr ptr, bool refcount = true)
 {
     Handle = new HandleRef (this, ptr);
     this.refcount = refcount;
     if (refcount)
     AddRef (this, ptr);
 }
        public TesseractEngine(string datapath, string language, EngineMode engineMode = EngineMode.Default)
        {
            DefaultPageSegMode = PageSegMode.Auto;
            handle = new HandleRef(this, Interop.TessApi.BaseApiCreate());

            Initialise(datapath, language, engineMode);
        }
Пример #27
0
 static internal extern /*SQLRETURN*/ODBC32.RetCode SQLBindCol(
     /*SQLHSTMT*/OdbcStatementHandle StatementHandle,
     /*SQLUSMALLINT*/UInt16 ColumnNumber,
     /*SQLSMALLINT*/ODBC32.SQL_C TargetType,
     /*SQLPOINTER*/HandleRef TargetValue,
     /*SQLLEN*/IntPtr BufferLength,
     /*SQLLEN* */IntPtr StrLen_or_Ind);
        // impersonate a given token
        protected void ImpersonateToken(HandleRef token) {
            try {
                // first revert
                _savedToken = new HandleRef(this, GetCurrentToken());

                if (_savedToken.Handle != IntPtr.Zero) {
                    if (UnsafeNativeMethods.RevertToSelf() != 0) {
                        _reverted = true;
                    }
                }

                // impersonate token if not zero
                if (token.Handle != IntPtr.Zero) { 
                    if (UnsafeNativeMethods.SetThreadToken(IntPtr.Zero, token.Handle) == 0) {
                        throw new HttpException(SR.GetString(SR.Cannot_impersonate));
                    }

                    _impersonating = true;
                }
            }
            catch {
                RestoreImpersonation();
                throw;
            }
        }
Пример #29
0
        protected override HandleRef BuildWindowCore(HandleRef hwndParent)
        {
            if (m_classAtom == 0)
            {
                WNDCLASS wind_class = new WNDCLASS
                {
                    lpszClassName = ClassName,
                    lpfnWndProc = WndProcPtr,
                };

                m_classAtom = Import.RegisterClassW(ref wind_class);
            }

            // create window
            Hwnd = Import.CreateWindowExW(
                0, // ex flag
                ClassName,
                "EmptyHwndTitle",
                WS.WS_CHILD,
                Import.CW_USEDEFAULT,
                Import.CW_USEDEFAULT,
                Import.CW_USEDEFAULT,
                Import.CW_USEDEFAULT,
                hwndParent.Handle,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
            );

            LostMouseCapture += EmptyHwnd_LostMouseCapture;

            return new HandleRef(this, Hwnd);
        }
 private void Dispose(bool disposing) {
     if (_savedToken.Handle != IntPtr.Zero) {
         try {} finally {
             UnsafeNativeMethods.CloseHandle(_savedToken.Handle);
             _savedToken = new HandleRef(this, IntPtr.Zero);
         }
     }
 }