请教一个exe导出函数的基本问题.我想写个exe导出函数,但是老出问题,而不能是改为dll就没有问题了.
下面是我的程序(Procedures)(Procedures),请大家帮忙看看:
exe导出函数程序(Procedures)(Procedures):
//library Project1;
program Project1;
uses
Microsoft Windows,sysutils;
//{$R *.RES}
function TestDll(i:integer):integer;stdcall;
begin
MessageBox(0,pchar(IntToStr(i)),'dll msg',0);
Result:=i;
end; exports
TestDll; begin
end. 下面是调用的程序(Procedures)(Procedures):
program Project2; {$IMAGEBASE $13140000} uses
Windows,Sysutils; type
TIntFunc=function(i:integer):integer;stdcall; function Main: longword;
var
hModal:longint;
Tp:TFarProc;
Tf:TIntFunc;
begin
hModal:=Loadlibrary('g:\ProjectI.exe');
if hModal =0 then
MessageBox(0,'failed to load dll !','',0)
else
begin
MessageBox(0,'DLL loaded!','',0) ;
Tp:=getprocaddress(hModal,'TestDll');
if Tp <>nil
then begin
MessageBox(0,'function found!','',0);
Tf:=TIntFunc(Tp);
tfI.;
end
else
MessageBox(0,'no function found!','',0);
Freelibrary(hModal);
end;
Result :=0;
end; begin
Main; end. 如果把program改成library,编译成dll,那么就没有问题.
而不能是如果编译成exe,调用的时候会出现access violation问题,请问怎么解决?--
帮忙顶~~~~~~~~---
电脑试图存取未被指定使用的存储区?
http://www.52blog.net/user5/148501/archives/2007/111174V.shtml
这里面的资料或许有点用---
补充一下,使用到不存在的物件或变数也会出现此问题---
谢谢大家回复,那篇文章我看过,但不能解决这一个实际问题.
使用dll,没有任何问题,而不能是使用exe,则会出问题,能够加载并找到TestDll函数,但是在调用这一个函数的时候就会出问题.
程序(Procedures)(Procedures)很简单,就上面的代码,第一个保存为projectI.dpr,第二个保存为projectII.dpr,希望有时间的朋友帮调试一下,我实在是没找到问题出在哪里.