Пример #1
0
        /// <summary>
        /// 初始化对象
        /// </summary>
        /// <param name="hwnd">窗体句柄</param>
        public Win32Caret(IntPtr hwnd)
        {
            Win32Handle handle = new Win32Handle();

            handle.handle = hwnd;
            myControl     = handle;
        }
Пример #2
0
        /// <summary>
        /// 初始化对象
        /// </summary>
        /// <param name="hwnd">窗体句柄</param>
        public Win32Caret(int hwnd)
        {
            Win32Handle handle = new Win32Handle();

            handle.handle = new IntPtr(hwnd);
            myControl     = handle;
        }
Пример #3
0
 public Win32Caret(int hwnd)
 {
     this._myControl = null;
     var handle = new Win32Handle {
         handle = new IntPtr(hwnd)
     };
     this._myControl = handle;
 }
Пример #4
0
 public Win32Caret(IntPtr hwnd)
 {
     this._myControl = null;
     var handle = new Win32Handle
     {
         handle = hwnd
     };
     this._myControl = handle;
 }
    [PlatformSpecific(TestPlatforms.Windows)] // ThreadPoolBoundHandle.BindHandle is not supported on Unix
    public void BindHandle_DisposedSyncHandleAsHandle_ThrowsArgumentException()
    {
        Win32Handle handle = HandleFactory.CreateSyncFileHandleFoWrite();

        handle.Dispose();

        AssertExtensions.Throws <ArgumentException>("handle", () =>
        {
            ThreadPoolBoundHandle.BindHandle(handle);
        });
    }
    [PlatformSpecific(TestPlatforms.Windows)] // ThreadPoolBoundHandle.BindHandle is not supported on Unix
    public void BindHandle_ClosedAsyncHandleAsHandle_ThrowsArgumentException()
    {
        using (Win32Handle handle = HandleFactory.CreateAsyncFileHandleForWrite())
        {
            handle.CloseWithoutDisposing();

            AssertExtensions.Throws <ArgumentException>("handle", () =>
            {
                ThreadPoolBoundHandle.BindHandle(handle);
            });
        }
    }
Пример #7
0
    private static unsafe Win32Handle CreateHandle(bool async, string fileName)
    {
        Win32Handle handle = DllImport.CreateFile(
            fileName,
            DllImport.FileAccess.GenericWrite,
            DllImport.FileShare.Write,
            IntPtr.Zero,
            DllImport.CreationDisposition.CreateAlways,
            async ? DllImport.FileAttributes.Overlapped : DllImport.FileAttributes.Normal,
            IntPtr.Zero);

        if (!handle.IsInvalid)
        {
            return(handle);
        }

        int    errorCode = Marshal.GetLastWin32Error();
        string filePath  = Path.GetFullPath(fileName);
        string message   =
            $"CreateFile or CreateFile2 failed (error code {errorCode}): {new Win32Exception(errorCode).Message}{Environment.NewLine}" +
            $"    File name: {fileName}{Environment.NewLine}" +
            $"    File path: {filePath}{Environment.NewLine}";

        if (Directory.Exists(Path.GetDirectoryName(filePath)))
        {
            try
            {
                File.WriteAllText(filePath, string.Empty);
                message += "    Successfully wrote to the file.";
            }
            catch (Exception ex)
            {
                message += $"    Failed to write to the file: {ex}";
            }
        }
        else
        {
            message += $"    Directory does not exist.";
        }

        throw new IOException(message);
    }
Пример #8
0
        public override async Task ReceiveAsync(Context context)
        {
            IAgentHandle handle;

            switch (context.HandleType)
            {
            case HandleType.Win32_CloseScreen:
                handle = new Win32Handle();
                break;

            case HandleType.Aforge_Camera:
                handle = new CameraHandle();
                break;

            default:
                handle = null;
                break;
            }
            await handle.ReceiveAsync(context);

            await handle.SendAsync(context);
        }
Пример #9
0
 /// <summary>
 /// 初始化对象
 /// </summary>
 /// <param name="handle">窗体句柄</param>
 public WindowInformation(IntPtr handle)
 {
     myControl = new Win32Handle(handle);
 }