Delphi动态调用DLL问题,很诡异,求帮忙,快哭 了……
自己编的一个程序,DLL也是我用delphi2010写的
静态调用dll时没问题,动态调用时出现错误,调用此dll里其它函数没有问题;
如果是函数内部使用了delphi自己的类型,那我传递出来了是shortstring类型啊
源代码:http://l5.yunpan.cn/lk/Q8biwcnFXEpgm
运行formtest.exe 可以看效果
delphi dll
[解决办法]
unit4 做如下修改:
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, {sharemem}; // 去掉sharemem,这个不是放这里的
program formtest;
uses
ShareMem, // 加在这里
Forms,
dialogs,
Unit4 in 'Unit4.pas' {Form4};
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm4, Form4);
Application.Run;
end.
=====================
function geturlstringdynamic(): shortstring;
type
TFunc = function(x:Integer): shortstring; stdcall; // 你DLL中函数原型必须匹配
var
Th: Thandle;
Tf: TFunc;
Tp: TFarProc;
begin
Th := LoadLibraryw('findie.dll');
@Tf := GetProcAddress(Th, 'GetIEUrl');
result := Tf(111);
freelibrary(th);
end;
==================
findie.dll 做如下修改:
function GetIEUrl(x: integer): shortstring; stdcall;
var
DDE: TDdeClientConv;
bret: boolean;
presult: pansichar;
sresult: shortstring;
begin
// dde := TDdeClientConv.Create(dde); 改为下面
dde := TDdeClientConv.Create(nil);
dde.OpenLink;
bret := DDE.SetLink('Iexplore', 'WWW_GetWindowInfo');
if bret then
begin
presult := dde.RequestData('0xFFFFFFFF,sURL, sTitle');
sresult := shortstring(presult);
result := shortstring(geturlstring(sresult));
dde.CloseLink;
dde.free;
//result:='15s';
end
else
begin
result := 'no ie';
end;
end;
最后重写build所有项目