我的库代码:
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;interfaceuses
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}
typemypointer=function(var DllVersion:PAnsiChar):WORD;procedure TForm1.Button1Click(Sender: TObject);varHinst: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.
加载动态库可以函数执行不了是什么原因,哪位高手帮我调试下
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;interfaceuses
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}
typemypointer=function(var DllVersion:PAnsiChar):WORD;procedure TForm1.Button1Click(Sender: TObject);varHinst: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.
加载动态库可以函数执行不了是什么原因,哪位高手帮我调试下
解决方案 »
- 阿三加油
- 关于在ehlib中设置了下拉列表,就是picklist中add了内容
- table在open时如果先设定filter,并将filtered设为true,是否可以减小内存的消耗?
- DBGRID中MOUSEDOWN问题,很奇怪!
- 这个函数的效率怎么那么低?求助!
- 请问GUAGE的用法
- 为什么不能Update?
- 怎么使用db contral组件改变数据库里的数据?比如dbmemo,偶记得好象要调用datasource的edit,post属性,但究竟应该怎么做?
- sqlserver7的一个问题!!!!!很急!
- Hi!给点帮助,好吗?
- socket使用writebuf时,16进制的数据如何双位取反?
- 请教,TM2008或QQ2009窗口什么了什么技术,为什么不能获得所需要控件的句柄信息。
mypointer=function(var DllVersion:PAnsiChar):WORD; stdcall;
还有个问题要请教,就是在主程序中必须为这个变量分配空间是为什么
version := StrAlloc(200);
如果用VC动态调用的话,这个参数应该是什么类型的.
你在 delphi可以用 cardinal, dword在 vc 里可以用 unsigned int, dword 等等