例如我有 TEST.exe和TEST.dll,我想获取TEST.dll中TTWW.pas中的一个变量A
于是我在TEST.dll中这样写use
TTWWin TTWW.pas' {FrmTTWW},
function Execute: string;
begin
Result :=A;
end;
{$R *.res}
exports
Execute;然后exe中接收,代码如下:implementation
function Execute: string; external 'Dll.dll' name 'Execute';procedure TTWWForm.Button2Click(Sender: TObject);
var
pExecute: function : string;
nHandle: THandle;
begin
nHandle := LoadLibrary('Dll.dll');
if nHandle <> INVALID_HANDLE_VALUE then
try
@pExecute := GetProcAddress(nHandle, 'Execute');
if Assigned(pExecute) then
Caption := pExecute();
finally
FreeLibrary(nHandle);
end;
end;可是我exe中接受到的Execute总是为空值.
当我把DLL中的Execute函数下面这样写是就成功了:function Execute: string;
begin
Result :='搞笑吧,静态值可以';
end;
请问我这是哪里出错了呢?
于是我在TEST.dll中这样写use
TTWWin TTWW.pas' {FrmTTWW},
function Execute: string;
begin
Result :=A;
end;
{$R *.res}
exports
Execute;然后exe中接收,代码如下:implementation
function Execute: string; external 'Dll.dll' name 'Execute';procedure TTWWForm.Button2Click(Sender: TObject);
var
pExecute: function : string;
nHandle: THandle;
begin
nHandle := LoadLibrary('Dll.dll');
if nHandle <> INVALID_HANDLE_VALUE then
try
@pExecute := GetProcAddress(nHandle, 'Execute');
if Assigned(pExecute) then
Caption := pExecute();
finally
FreeLibrary(nHandle);
end;
end;可是我exe中接受到的Execute总是为空值.
当我把DLL中的Execute函数下面这样写是就成功了:function Execute: string;
begin
Result :='搞笑吧,静态值可以';
end;
请问我这是哪里出错了呢?
解决方案 »
- RemObjects 如何查询oracle中带long类型的表???(分不够再加)
- 请教一个TListView的自绘SubItem的问题
- treeview的问题
- 哪位朋友开发过手机短信的群发软件
- DELPHI如何实现恢复sql server数据库?
- 如何实现gif动画的旋转
- 是不是PB的程序员特别大方,DELPHI的程序员就特别小气?????
- 怎样把得到的数据动态的写入SQL Server2000中
- 这段代码是怎么起作用的?
- 我在一台计算机上面使用了ODBC,当我把程序那道别的机器上面运行的时候用从新配置ODBC吗? 如果需要,我该如何得让程序区配置呢?
- 谁有Installaware 7.0的安装密码,快给我一个
- 求一个delphi与asp网站交互的例子
begin
aStr :=A;
end;另外,既然A是dll中的全局变量,楼主在dll中如何给这个全局变量赋值的呢?
A的值是这样的,我有一个treelist,我在改变node时A的值也会不停变化.
在dxTreeList1MouseDown事件中赋值了
地址恢复出string,这个俺经常用。
dll的修改大致如下:
function Execute(pRet:PChar,nLen:Integer): string;
begin
//Result :=A;
StrLCopy(pRet,A,nLen);
end;然后在exe调用的时候先声明一个字符数组,把数组指针和长度传递给Execute,当然需要考虑好数组的大小要足够保存A的字符串的值了
你的转述的东西只有前一半是靠谱的,后面的结论跟为什么引用ShareMem根本没关系。
由于各个module都有自己的memory manager,所以由rtl自动管理生存期的变量会出现由module A分配内存,却在module B中生存期结束由B的mm释放内存的情况。引用ShareMem或者使用fastmm的目的只有一个,就是让不同module使用同一个mm,这样就不会出现不同的mm无法管理其它module自动生存期类型的释放问题
string类型时需要uses sharemem并且放在第一个