急急急!怎样调用Exe的输出函数?到底出了什么错? ( 积分: 100 )

  • 主题发起人 主题发起人 newshenliang
  • 开始时间 开始时间
N

newshenliang

Unregistered / Unconfirmed
GUEST, unregistred user!
据说可以像调用DLL一样调用Exe的输出函数,不知道怎么一直试都不行, 请大家帮帮忙!<br>十分感谢!<br>下面是我从论坛中搜索到的,说是可以调用,可在我这就是不行!我的编译器是Delphi7!<br>program TestExe; //输出函数的Exe<br>uses<br> &nbsp;Windows;<br>procedure Test(p: PChar); export; stdcall;<br>begin<br> &nbsp;MessageBox(0, p, 'Test', MB_OK);<br>end;<br>exports<br> &nbsp;Test;<br>begin<br>end.<br><br>procedure TForm1.Button1Click(Sender: TObject); //另一APP中调用<br>var<br> &nbsp;lib: THandle;<br> &nbsp;Test: procedure(p: PChar); stdcall;<br>begin<br> &nbsp;lib := LoadLibrary('TestExe.exe');<br> &nbsp;if lib = 0 then<br> &nbsp; &nbsp;ShowError('Cannot load the module')<br> &nbsp;else<br> &nbsp;begin<br> &nbsp; &nbsp;@Test := GetProcAddress(lib, 'Test');<br> &nbsp; &nbsp;if @Test = nil then<br> &nbsp; &nbsp; &nbsp;ShowError('Cannot GetProcAddress')<br> &nbsp; &nbsp;else Test('This is a test');//出现地址错误,为什么呢???<br> &nbsp; &nbsp;FreeLibrary(lib);<br> &nbsp;end;<br>end;<br><br>十分急,先谢谢大家!
 
据说可以像调用DLL一样调用Exe的输出函数,不知道怎么一直试都不行, 请大家帮帮忙!<br>十分感谢!<br>下面是我从论坛中搜索到的,说是可以调用,可在我这就是不行!我的编译器是Delphi7!<br>program TestExe; //输出函数的Exe<br>uses<br> &nbsp;Windows;<br>procedure Test(p: PChar); export; stdcall;<br>begin<br> &nbsp;MessageBox(0, p, 'Test', MB_OK);<br>end;<br>exports<br> &nbsp;Test;<br>begin<br>end.<br><br>procedure TForm1.Button1Click(Sender: TObject); //另一APP中调用<br>var<br> &nbsp;lib: THandle;<br> &nbsp;Test: procedure(p: PChar); stdcall;<br>begin<br> &nbsp;lib := LoadLibrary('TestExe.exe');<br> &nbsp;if lib = 0 then<br> &nbsp; &nbsp;ShowError('Cannot load the module')<br> &nbsp;else<br> &nbsp;begin<br> &nbsp; &nbsp;@Test := GetProcAddress(lib, 'Test');<br> &nbsp; &nbsp;if @Test = nil then<br> &nbsp; &nbsp; &nbsp;ShowError('Cannot GetProcAddress')<br> &nbsp; &nbsp;else Test('This is a test');//出现地址错误,为什么呢???<br> &nbsp; &nbsp;FreeLibrary(lib);<br> &nbsp;end;<br>end;<br><br>十分急,先谢谢大家!
 
procedure Test(p: PChar); export; stdcall;<br>begin<br> &nbsp;Showmessage(p);<br>end;
 
xianguo:<br> &nbsp;先谢谢你!但还是有问题,Test('This is a test');//依然出现地址错误,为什么呢???
 
'This is a test'改为PCHAR的变量传试一下,是不是可以?
 
尝试Test(PChar('This is a test'));
 
还是不行,只好换用其它方法了!发分了!
 

Similar threads

I
回复
0
查看
878
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
520
import
I
后退
顶部