静态调用 ActiveX DLL 要如何宣告

bobogg 2011-06-26 11:08:49
VB6 写了一个 ActiveX DLL 名为 A_03.DLL

菜单 -> Component -> Import Component -> Import Type Library -> Creat Unit


得到 A_03_TLB 内容如下




unit A_03_TLB;

{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}
{$VARPROPSETTER ON}
{$ALIGN 4}
interface

uses Windows, ActiveX, Classes, Graphics, OleServer, StdVCL, Variants;


// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:
// Type Libraries : LIBID_xxxx
// CoClasses : CLASS_xxxx
// DISPInterfaces : DIID_xxxx
// Non-DISP interfaces: IID_xxxx
// *********************************************************************//
const
// TypeLibrary Major and minor versions
A_03MajorVersion = 3;
A_03MinorVersion = 0;

LIBID_A_03: TGUID = '{DAD4FAA2-CD2A-4F07-BA7A-687F5E7A4B27}';

IID__Test: TGUID = '{72B3C6DC-4F23-4954-ACF6-5ACF102BE864}';
CLASS_Test: TGUID = '{3799C0FE-7D12-4C5D-A01E-422F6F496DCE}';
type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
_Test = interface;
_TestDisp = dispinterface;

// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
Test = _Test;


// *********************************************************************//
// Interface: _Test
// Flags: (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID: {72B3C6DC-4F23-4954-ACF6-5ACF102BE864}
// *********************************************************************//
_Test = interface(IDispatch)
['{72B3C6DC-4F23-4954-ACF6-5ACF102BE864}']
procedure a_01(var a: Single); safecall;
procedure a_02(var a: Double); safecall;
procedure A_03(var a: WideString); safecall;
end;

// *********************************************************************//
// DispIntf: _TestDisp
// Flags: (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID: {72B3C6DC-4F23-4954-ACF6-5ACF102BE864}
// *********************************************************************//
_TestDisp = dispinterface
['{72B3C6DC-4F23-4954-ACF6-5ACF102BE864}']
procedure a_01(var a: Single); dispid 1610809344;
procedure a_02(var a: Double); dispid 1610809345;
procedure A_03(var a: WideString); dispid 1610809346;
end;

// *********************************************************************//
// The Class CoTest provides a Create and CreateRemote method to
// create instances of the default interface _Test exposed by
// the CoClass Test. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoTest = class
class function Create: _Test;
class function CreateRemote(const MachineName: string): _Test;
end;

implementation

uses ComObj;

class function CoTest.Create: _Test;
begin
Result := CreateComObject(CLASS_Test) as _Test;
end;

class function CoTest.CreateRemote(const MachineName: string): _Test;
begin
Result := CreateRemoteComObject(MachineName, CLASS_Test) as _Test;
end;

end.



以下是 Unit3.dfm 内容



unit Unit3;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm3 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
var

MyDLL : Test; -----> 这一步要 "明确" 宣告型态,
为了顾及执行速度 "不能" 宣告为 MyDLL: OleVariant;
MyDLL :=CreateOleObject(......);

begin

MyDLL.a_01(); // 呼叫.....
MyDLL.a_02();

end;




=== 请问如何宣告 ========================================================

MyDLL : Test; -----> 这一步要 宣告为 "明确" 型态,
为了顾及执行速度 "不能" 宣告为 MyDLL: OleVariant; MyDLL :=CreateOleObject(...........);


上面 MyDLL : Test; 的宣告编译错误, 请问如何宣告才是正确的
...全文
119 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
bobogg 2011-06-28
  • 打赏
  • 举报
回复
有大大知道吗
bobogg 2011-06-27
  • 打赏
  • 举报
回复
可以了

但是执行时 出错: read address 00000000

为了测试我改用 a.a_00(); 无参数

还是出错: read address 00000000

我知道是 VB6 和 delphi 格式问题但是就是不知道如何修正

把 safecall 改为 stdcall 还是不行

procedure a_01(a: Single); stdcall;
procedure a_02(var a: Double); stdcall;
procedure A_03(var a: WideString); stdcall;
procedure a_00; stdcall;


yqdragon 2011-06-26
  • 打赏
  • 举报
回复
直接用

uses
A_03_TLB;

var
a:_Test;
begin
a.a_01(参数);

end;

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧