private static void GetGlobalMemoryStatus(ref UnsafeNativeMethods.MEMORYSTATUSEX memoryStatus)
 {
     memoryStatus.dwLength = (uint) Marshal.SizeOf(typeof(UnsafeNativeMethods.MEMORYSTATUSEX));
     if (!UnsafeNativeMethods.GlobalMemoryStatusEx(ref memoryStatus))
     {
         int error = Marshal.GetLastWin32Error();
         throw FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activation.SR.Hosting_GetGlobalMemoryFailed, new Win32Exception(error)));
     }
 }
 protected override bool ReleaseHandle()
 {
     return(UnsafeNativeMethods.CloseHandle(base.handle) != 0);
 }
Пример #3
0
        unsafe int ReceiveCoreAsync(MsmqQueueHandle handle, IntPtr nativePropertiesPointer, TimeSpan timeout,
                                    int action, NativeOverlapped* nativeOverlapped,
                                    UnsafeNativeMethods.MQReceiveCallback receiveCallback)
        {
            int timeoutInMilliseconds = TimeoutHelper.ToMilliseconds(timeout);

            return UnsafeNativeMethods.MQReceiveMessage(handle, timeoutInMilliseconds, action,
                                                        nativePropertiesPointer, nativeOverlapped, receiveCallback,
                                                        IntPtr.Zero, (IntPtr)UnsafeNativeMethods.MQ_NO_TRANSACTION);
        }
Пример #4
0
        public static unsafe bool TryCreate(List <SecurityIdentifier> allowedSids, Uri pipeUri, string sharedMemoryName, out PipeSharedMemory result)
        {
            byte[] buffer;
            SafeFileMappingHandle handle;
            int    num;
            bool   flag2;
            Guid   guid     = Guid.NewGuid();
            string pipeName = BuildPipeName(guid);

            try
            {
                buffer = SecurityDescriptorHelper.FromSecurityIdentifiers(allowedSids, -2147483648);
            }
            catch (Win32Exception exception)
            {
                Exception innerException = new PipeException(exception.Message, exception);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(innerException.Message, innerException));
            }
            result = null;
            fixed(byte *numRef = buffer)
            {
                UnsafeNativeMethods.SECURITY_ATTRIBUTES securityAttributes = new UnsafeNativeMethods.SECURITY_ATTRIBUTES {
                    lpSecurityDescriptor = numRef
                };
                handle = UnsafeNativeMethods.CreateFileMapping((IntPtr)(-1), securityAttributes, 4, 0, sizeof(SharedMemoryContents), sharedMemoryName);
                num    = Marshal.GetLastWin32Error();
            }

            if (handle.IsInvalid)
            {
                handle.SetHandleAsInvalid();
                if (num == 5)
                {
                    return(false);
                }
                Exception exception3 = new PipeException(System.ServiceModel.SR.GetString("PipeNameCantBeReserved", new object[] { pipeUri.AbsoluteUri, PipeError.GetErrorString(num) }), num);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new AddressAccessDeniedException(exception3.Message, exception3));
            }
            if (num == 0xb7)
            {
                handle.Close();
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreatePipeNameInUseException(num, pipeUri));
            }
            PipeSharedMemory memory = new PipeSharedMemory(handle, pipeUri, pipeName);
            bool             flag   = true;

            try
            {
                memory.InitializeContents(guid);
                flag   = false;
                result = memory;
                flag2  = true;
            }
            finally
            {
                if (flag)
                {
                    memory.Dispose();
                }
            }
            return(flag2);
        }