apicaller.pas
来自「delphi开发语言下的源代码分析」· PAS 代码 · 共 42 行
PAS
42 行
unit ApiCaller;
interface
uses
Windows, SysUtils;
resourcestring
SApiCallerError = 'Api Call Error: %s (%d)';
type
EApiCaller = class(Exception);
TApiCaller = class
protected
procedure CheckThreadError(ErrCode: Integer); overload;
procedure CheckThreadError(Success: Boolean); overload;
public
function GetDC(hwnd: HWND) : HDC;
// ... 更多的API
end;
implementation
procedure TApiCaller.CheckThreadError(ErrCode: Integer);
begin
if ErrCode <> 0 then
raise EApiCaller.CreateResFmt(@SApiCallerError, [SysErrorMessage(ErrCode), ErrCode]);
end;
procedure TApiCaller.CheckThreadError(Success: Boolean);
begin
if not Success then
CheckThreadError(GetLastError);
end;
function TApiCaller.GetDC(hwnd: HWND) : HDC;
begin
Result := windows.GetDC(hwnd);
CheckThreadError(Result <> 0);
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?