public SingleInstanceManager(string moniker) { int error = NativeConstants.ERROR_SUCCESS; if (moniker.IndexOf('\\') != -1) { throw new ArgumentException("moniker must not have a backslash character"); } this.mappingName = "Local\\" + moniker; this.hFileMapping = SafeNativeMethods.CreateFileMappingW( NativeConstants.INVALID_HANDLE_VALUE, IntPtr.Zero, NativeConstants.PAGE_READWRITE | NativeConstants.SEC_COMMIT, 0, mappingSize, mappingName); error = Marshal.GetLastWin32Error(); if (this.hFileMapping == IntPtr.Zero) { throw new Win32Exception(error, "CreateFileMappingW() returned NULL (" + error.ToString() + ")"); } this.isFirstInstance = (error != NativeConstants.ERROR_ALREADY_EXISTS); }