Пусть есть такая библиотека:
| Код | library Project1;
uses SysUtils, Classes, Windows;
type itPoint3f = interface procedure Normalize(); procedure SetValue(x, y, z:real); procedure output(); end;
tPoint3f=class(TInterfacedObject, itPoint3f) x,y,z:real; procedure Normalize(); procedure SetValue(x, y, z:real); procedure output(); Destructor Destroy();override; end;
procedure tPoint3f.SetValue; begin self.x:=x; self.y:=y; self.z:=z; end;
Destructor tPoint3f.Destroy(); begin end;
procedure tPoint3f.Normalize; var t:real; begin t:=sqrt(x*x+y*y+z*z); x:=x/t; y:=y/t; z:=z/t; end;
procedure tPoint3f.output; begin writeln(x:-1:4,' ', y:-1:4, ' ', z:-1:4); end;
function Get_itPoint3f(out intf: itPoint3f): boolean; begin Result := True; try intf := tPoint3f.Create; except Result := False; intf := nil; end; end;
function Del_itPoint3f(out intf: itPoint3f): boolean; begin tPoint3f(intf).Free; result:=true; end;
exports Get_itPoint3f, Del_itPoint3f;
begin end.
|
Вот так в Delphi гружу:
| Код | program Project2;
{$APPTYPE CONSOLE}
uses SysUtils;
type itPoint3f = interface procedure Normalize(); procedure SetValue(x, y, z:real); procedure output(); end;
procedure Get_itPoint3f(out intf: itPoint3f); stdcall;external 'Project1.dll' name 'Get_itPoint3f'; function Del_itPoint3f(out intf: itPoint3f): boolean;stdcall;external 'Project1.dll' name 'Del_itPoint3f';
procedure main; var t:itPoint3f; begin Get_itPoint3f(t); t.SetValue(1,1,1); t.Normalize(); t.output();
Del_itPoint3f(t); readln; end;
begin { TODO -oUser -cConsole Main : Insert code here } main; end.
|
Вопросы: 1) Правильно ли удаляется объект в Del_itPoint3f ? 2) После readln возникает исключение "access violation at 0x0000000000 ". Почему? 3) Как такой класс импортировать в С++?
Заранее признетелен..
|