Доброго дня господа !
Цель - Создание DLL для использования НЕ только DELPHI-ой
Имею
Unit Interface
----------------------------------------------
unit InterfaceList;
interface
type
IMyInterface = Interface
['{0806339A-4EDD-48A5-A60A-54E6E9AF94E1}']
function Substr(Const aStr: WideString; Index, Count: Integer): WideString;
end;
implementation
end.
----------------------------------------------
Unit своего объекта
----------------------------------------------
unit ObjectList;
interface
uses
Dialogs,
InterfaceList;
type
TMyClass = class(TInterfacedObject, IMyInterface)
private
protected
public
destructor Destroy; override;
function Substr(Const aStr: WideString; Index, Count: Integer): WideString;
end;
{$R *.res}
implementation
function TMyClass.Substr(Const aStr: WideString; Index, Count: Integer): WideString;
begin
Result:=Copy(aStr,Index,Count);
end;
destructor TMyClass.Destroy;
begin
ShowMessage('Destroy');
inherited;
end;
end.
----------------------------------------------
Unit Dll-Library
----------------------------------------------
library DllLibrary;
uses
ComServ,
InterfaceList in 'InterfaceList.pas',
ObjectList in 'ObjectList.pas';
{$R *.res}
function CreateMyClass: IMyInterface; stdcall;
begin
Result:=TMyClass.Create;
end;
function ReturnValue: Integer; stdcall;
begin
Result:=100;
end;
exports
CreateMyClass,
ReturnValue,
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;
begin
end.
----------------------------------------------
Unit инициирующий вызов
----------------------------------------------
unit DllMain;
interface
uses
Forms, StdCtrls, Controls, Classes, InterfaceList, SysUtils, Dialogs;
type
TfrMain = class(TForm)
edMain: TEdit;
lbMain: TLabel;
btMain: TButton;
Button1: TButton;
procedure btMainClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frMain: TfrMain;
function CreateMyClass: IMyInterface; stdcall; external 'DllLibrary.dll';
function ReturnValue: Integer; stdcall; external 'DllLibrary.dll'
implementation
{$R *.dfm}
procedure TfrMain.btMainClick(Sender: TObject);
var
dllObject: IMyInterface;
begin
dllObject:=CreateMyClass;
lbMain.Caption:=dllObject.Substr(edMain.Text,1,10);
end;
procedure TfrMain.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(ReturnValue));
end;
end.
----------------------------------------------
Возникли вопросы
- зачем создан дополнительный класс IMyInterface,разве невозможно
сослаться непосредственно на TMyClass.
Поясните пожалуйста ...
- как вызвать функцию ReturnValue (даже не класс) из VBS
VBS - скрипт прилагаю
----------------------------------------------
Dim lb
On Error Resume Next
Err.Clear
MsgBox "Create Dll"
Set lb = CreateObject("DllLibrary.ReturnValue")
MsgBox Err.Source & "_" & Err.Description & "_" & Err.Number
On Error Goto 0
MsgBox "Exit"
----------------------------------------------
Заранее благодарен !