关于DEPHI动态库的问题

moruo2002 2008-05-27 06:49:15
我的库代码:
library TEST;
uses
SysUtils,
Classes;

{$R *.res}
function GetDllVersion(var DllVersion:PAnsiChar):WORD;stdcall;
var
l_str: string;
begin
//DllVersion := StrAlloc(55);
l_str:= '0081'
+ '0100'
+ '0001'
+ '0008';
//DllVersion:= StrCopy(DllVersion,PChar(l_str));
StrCopy(DllVersion,PChar(l_str));
//l_str:= strpas(DllVersion);
result:= $9000;

end;
exports
GetDllVersion;
begin
end.
然后生成了库,调用时候有错误
主程序如下.
unit Unit2;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
type

mypointer=function(var DllVersion:PAnsiChar):WORD;

procedure TForm1.Button1Click(Sender: TObject);

var

Hinst:Thandle;

showform:mypointer;
state : WORD;
version : PAnsiChar;
begin
version := StrAlloc(200);
Hinst:=loadlibrary('test.dll');//Load一个Dll,按文件名找。

showform:=getprocaddress(Hinst,'GetDllVersion');//按函数名找,大小写敏感。

state :=showform(version);//找到函数入口指针就调用。

Freelibrary(Hinst);
end;
end.
加载动态库可以函数执行不了是什么原因,哪位高手帮我调试下
...全文
67 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
大大怪老张 2008-05-28
  • 打赏
  • 举报
回复
貌似上面的回复有点问题,
你在 delphi可以用 cardinal, dword

在 vc 里可以用 unsigned int, dword 等等
大大怪老张 2008-05-28
  • 打赏
  • 举报
回复
DWORD 或者其他 windows 平台通用的整型数据类型
moruo2002 2008-05-27
  • 打赏
  • 举报
回复
再来个高手看下啊
moruo2002 2008-05-27
  • 打赏
  • 举报
回复
嗯,好了,谢谢!
还有个问题要请教,就是在主程序中必须为这个变量分配空间是为什么
version := StrAlloc(200);
如果用VC动态调用的话,这个参数应该是什么类型的.
budded 2008-05-27
  • 打赏
  • 举报
回复
function GetDllVersion(var DllVersion:PAnsiChar):WORD;stdcall;
mypointer=function(var DllVersion:PAnsiChar):WORD; stdcall;

16,748

社区成员

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

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