본문 바로가기
Delphi/문법

인터페이스에 오브젝트 얻기

by MonoSoft 2024. 5. 30.
728x90
반응형

인터페이스에 오브젝트 얻기

728x90

 

 

function GetImplementingObject(const I: IInterface): TObject;

const

AddByte = $04244483;

AddLong = $04244481;

type

PAdjustSelfThunk = ^TAdjustSelfThunk;

TAdjustSelfThunk = packed record

case AddInstruction: longint of

AddByte : (AdjustmentByte: shortint);

AddLong : (AdjustmentLong: longint);

end;

 

PInterfaceMT = ^TInterfaceMT;

 

TInterfaceMT = packed record

QueryInterfaceThunk: PAdjustSelfThunk;

end;

 

TInterfaceRef = ^PInterfaceMT;

 

var

QueryInterfaceThunk: PAdjustSelfThunk;

begin

Result := Pointer(I);

if Assigned(Result) then

try

QueryInterfaceThunk := TInterfaceRef(I)^. QueryInterfaceThunk;

case QueryInterfaceThunk.AddInstruction of

AddByte: Inc(PChar(Result), QueryInterfaceThunk.AdjustmentByte);

AddLong: Inc(PChar(Result), QueryInterfaceThunk.AdjustmentLong);

else

Result := nil;

end;

except

Result := nil;

end;

end;

728x90
반응형

댓글