this slowpoke moves

No double Execute Program

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  mHandle: THandle;



implementation

{$R *.dfm}

initialization
  mHandle := CreateMutex(nil, True, 'XYZ');
  if GetLastError = ERROR_ALREADY_EXISTS then
  begin
    ShowMessage('Program is already running!');
    halt;
  end;

finalization
  if mHandle <> 0 then CloseHandle(mHandle);

{
HANDLE CreateMutex(LPSECURITY_ATTRIBUTES lpMutexAttributes,
                   BOOL bInitialOwner,
                   LPCTSTR lpName);

lpMutexAttributes:
  Ignored. Must be NULL.

bInitialOwner:
  Boolean that specifies the initial owner of the mutex object.
  If this value is TRUE and the caller created the mutex,
  the calling thread obtains ownership of the mutex object.
  Otherwise, the calling thread does not obtain ownership of the mutex.

lpName:
  Long pointer to a null-terminated string specifying the name of the mutex object.
  The name is limited to MAX_PATH characters and can contain any character except the
  backslash path-separator character (\). Name comparison is case sensitive.

Return Values:
 A handle to the mutex object indicates success.
 If the named mutex object existed before the function call,
 the function returns a handle to the existing object and GetLastError
 returns ERROR_ALREADY_EXISTS.

}
end.
 

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate