컴터/delphi

동적 dll 링크

우렁씨 2007. 12. 10. 12:31

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
  var   ////동적 dll 만들기..
    iDllHandle : Integer;
    DllFunc : Function (a, b : Integer): Integer;  //해당 함수 레퍼런스 가지고 있게.
begin
  iDllHandle := LoadLibrary('dll1.dll');  //dll 파일 호출
  if iDllHandle >= 32 then begin ////32미만은 에러다.메모리에 올리기.
    @DllFunc := GetProcAddress(iDllHandle, 'Sum');//@는포인터로 바꿈

    if @DllFunc <> Nil then
      ShowMessage(IntToStr(DllFunc(1, 2)));

    FreeLibrary(iDllHandle);////dll 메모리 해제
  end;

end;