CJC Delphi 技巧馆's Archiver

cjc Posted at 2013-5-27 14:47

解决win7的 TCriticalSection 内存泄露问题

修改
   System.SyncObjs.pas 文件


type
  InitializeCriticalSectionExProc = function(var lpCriticalSection: TRTLCriticalSection;
                                             dwSpinCount: DWORD;
                                             Flags:       DWORD): BOOL; stdcall;
var
  kernel32: HModule;
  system_win7: Boolean;
  InitializeCriticalSectionExFunc: InitializeCriticalSectionExProc;
const
  CRITICAL_SECTION_NO_DEBUG_INFO = $01000000;

procedure Init;
begin
  system_win7 := CheckWin32Version(6, 0);
  if system_win7 then
  begin
    kernel32 := LoadLibrary('kernel32.dll');
    if kernel32 <> 0 then
      @InitializeCriticalSectionExFunc := GetProcAddress(kernel32, 'InitializeCriticalSectionEx');
  end;
end;

procedure UnInit;
begin
  if @InitializeCriticalSectionExFunc <> nil then
    @InitializeCriticalSectionExFunc := nil;
  if kernel32 <> 0 then
  begin
    FreeLibrary(kernel32);
    kernel32 := 0;
  end;
end;


{ TCriticalSection }

constructor TCriticalSection.Create;
var
  InitializeCriticalSection2: InitializeCriticalSectionExProc;
begin
  inherited Create;
  @InitializeCriticalSection2 := @InitializeCriticalSectionExFunc;
  if (system_win7) and (@InitializeCriticalSection2 <> nil) then
    InitializeCriticalSection2(FSection, 0, CRITICAL_SECTION_NO_DEBUG_INFO)
  else
    InitializeCriticalSection(FSection);
end;

Page: [1]
CJC好玩背单词最新版本 - 是目前最好的背单词软件,游戏好玩,功能强大,词库众多,还有真人语音,免费下载,免费试用 !

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.