コード例 #1
0
        private unsafe int WriteFileNative(SafeFileHandle handle, byte[] bytes, int offset, int count, out int hr)
        {
            // Don't corrupt memory when multiple threads are erroneously writing
            // to this stream simultaneously.  (the OS is reading from
            // the array we pass to WriteFile, but if we read beyond the end and
            // that memory isn't allocated, we could get an AV.)
            if (bytes.Length - offset < count)
            {
                throw new IndexOutOfRangeException("IORaceCondition");
            }

            // You can't use the fixed statement on an array of length 0.
            if (bytes.Length == 0)
            {
                hr = 0;
                return(0);
            }

            int numBytesWritten = 0;
            int r = 0;

            hr = 0;
            numBytesWritten = handle.WriteFile(bytes, offset, count);

            return(numBytesWritten);
        }
コード例 #2
0
        private static int WriteFileNative(SafeFileHandle hFile, byte[] bytes, int offset, int count)
        {
            // You can't use the fixed statement on an array of length 0.
            if (bytes.Length == 0)
            {
                return(ERROR_SUCCESS);
            }

            bool writeSuccess;

            int numBytesWritten = hFile.WriteFile(bytes, offset, count);

            writeSuccess = (0 != numBytesWritten);

            if (writeSuccess)
            {
                return(ERROR_SUCCESS);
            }

            int errorCode = -1;

            return(errorCode);
        }
コード例 #3
0
ファイル: __ConsoleStream.cs プロジェクト: afrog33k/csnative
        private static int WriteFileNative(SafeFileHandle hFile, byte[] bytes, int offset, int count)
        {
            // You can't use the fixed statement on an array of length 0.
            if (bytes.Length == 0)
                return ERROR_SUCCESS;

            bool writeSuccess;

            int numBytesWritten = hFile.WriteFile(bytes, offset, count);
            writeSuccess = (0 != numBytesWritten);

            if (writeSuccess)
                return ERROR_SUCCESS;

            int errorCode = -1;

            return errorCode;
        }