天天看點

隻運作一個執行個體以及記憶體洩漏檢測

unit 使應用程式隻運作一個執行個體;

interface

uses windows;

const

// - 互斥體唯一的名字

_mutex_name = ‘{19631971-1976-1981-1989-199319941995}‘;

var

_mutex_handle: thandle;

implementation

initialization // -

載入時調用的代碼

// - 建立互斥體對象

_mutex_handle := createmutex(nil,

false, lpcwstr(_mutex_name));

//

- 若互斥體對象存在則

if

getlasterror = error_already_exists then

// - 結束程式,可有 integer 參數給作業系統

halt(error_already_exists);

// -

工作在調試狀态時檢測記憶體洩漏

{$warn

symbol_platform off}

reportmemoryleaksonshutdown :=

boolean(debughook);

{$warn symbol_platform on}

finalization // -

釋放時調用的代碼

// - 釋放互斥體

releasemutex(_mutex_handle);

end.

繼續閱讀