Example #1
0
        internal PenContext CreateContext(IntPtr hwnd, PenContexts contexts)
        {
            PenContext penContext;
            bool       supportInRange = (this.TabletHardwareCapabilities & TabletHardwareCapabilities.HardProximity) != 0;
            bool       isIntegrated   = (this.TabletHardwareCapabilities & TabletHardwareCapabilities.Integrated) != 0;

            // Use a PenThread to create a tablet context so we don't cause reentrancy.
            PenContextInfo result = _penThread.WorkerCreateContext(hwnd, _tabletInfo.PimcTablet.Value);

            penContext = new PenContext(result.PimcContext != null ? result.PimcContext.Value : null,
                                        hwnd, contexts,
                                        supportInRange, isIntegrated, result.ContextId,
                                        result.CommHandle != null ? result.CommHandle.Value : IntPtr.Zero,
                                        Id);
            return(penContext);
        }
Example #2
0
            protected override void OnDoWork()
            {
                IPimcContext pimcContext;
                int id;
                Int64 commHandle;

                try
                {
                    _pimcTablet.CreateContext(_hwnd, true, 250, out pimcContext, out id, out commHandle);
                    // Set result data and signal we are done.
                    PenContextInfo result;
                    result.ContextId = id;
                    result.PimcContext = new SecurityCriticalDataClass<IPimcContext>(pimcContext);

                    // commHandle cannot be a IntPtr by itself because its native counterpart cannot be a
                    // INT_PTR. The reason being that INT_PTR (__int3264) always gets marshalled as a
                    // 32 bit value, which means in a 64 bit process we would lose the first half of the pointer.
                    // Instead with this we always get a 64 bit value and then instantiate the IntPtr appropriately
                    // so that nothing gets lost during marshalling. The cast from Int64 to Int32 below
                    // should be lossless cast because both COM server and client are expected
                    // to be of same bitness (they are in the same process).
                    result.CommHandle = new SecurityCriticalDataClass<IntPtr>((IntPtr.Size == 4 ? new IntPtr((int)commHandle) : new IntPtr(commHandle)));
                    
                    _result = result;
                }
                catch ( System.Runtime.InteropServices.COMException )
                {
                    // result will not be initialized if we fail due to a COM exception.
                    Debug.WriteLine("WorkerOperationCreateContext.OnDoWork failed due to a COMException");

                    // set with uninitialized PenContextInfo (all zero).
                    _result = new PenContextInfo();
                }
                catch ( System.ArgumentException )
                {
                    // result will not be initialized if we fail due to an ArgumentException.
                    Debug.WriteLine("WorkerOperationCreateContext.OnDoWork failed due to an ArgumentException");

                    // set with uninitialized PenContextInfo (all zero).
                    _result = new PenContextInfo();
                }
                catch ( System.UnauthorizedAccessException )
                {
                    // result will not be initialized if we fail due to an UnauthorizedAccessException.
                    Debug.WriteLine("WorkerOperationCreateContext.OnDoWork failed due to an UnauthorizedAccessException");

                    // set with uninitialized PenContextInfo (all zero).
                    _result = new PenContextInfo();
                }
            }
Example #3
0
            protected override void OnDoWork()
            { 
                IPimcContext pimcContext;
                int id; 
                IntPtr commHandle; 

                try 
                {
                    _pimcTablet.CreateContext(_hwnd, true, 250, out pimcContext, out id, out commHandle);
                    // Set result data and signal we are done.
                    PenContextInfo result; 
                    result.ContextId = id;
                    result.PimcContext = new SecurityCriticalDataClass<IPimcContext>(pimcContext); 
                    result.CommHandle = new SecurityCriticalDataClass<IntPtr>(commHandle); 
                    _result = result;
                } 
                catch ( System.Runtime.InteropServices.COMException )
                {
                    // result will not be initialized if we fail due to a COM exception.
                    Debug.WriteLine("WorkerOperationCreateContext.OnDoWork failed due to a COMException"); 

                    // set with uninitialized PenContextInfo (all zero). 
                    _result = new PenContextInfo(); 
                }
                catch ( System.ArgumentException ) 
                {
                    // result will not be initialized if we fail due to an ArgumentException.
                    Debug.WriteLine("WorkerOperationCreateContext.OnDoWork failed due to an ArgumentException");
 
                    // set with uninitialized PenContextInfo (all zero).
                    _result = new PenContextInfo(); 
                } 
                catch ( System.UnauthorizedAccessException )
                { 
                    // result will not be initialized if we fail due to an UnauthorizedAccessException.
                    Debug.WriteLine("WorkerOperationCreateContext.OnDoWork failed due to an UnauthorizedAccessException");

                    // set with uninitialized PenContextInfo (all zero). 
                    _result = new PenContextInfo();
                } 
            }