Free Pascal can't find entry point for dll
我是Pascal的新手。
我想在免费的pascal中调用.dll文件中的函数,并且在运行项目时出现以下错误:
过程入口点GetProcAddress不在动态链接库HNLib.dll中。
代码如下:
1 2 3 4 5 6 7 8 9 | Program Test; function GetProcAddress : Integer; cdecl; external 'HNLib.dll'; function GetProcAddress : Single; cdecl; external 'HNLib.dll'; procedure GetProcAddress( X : Single); cdecl; external 'HNLib.dll'; procedure GetProcAddress; cdecl; external 'HNLib.dll'; begin GetProcAddress( 5.5 ); readln; end. |
.pas文件和dll位于一个目录中。
请帮助我!
(此外,
您还需要在using子句中至少使用
有关更多信息,请参见LoadLibrary和GetProcAddress上的WinAPI文档。
对于刚开始的程序员,您可能会发现使用函数的静态链接而不是动态链接(使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | // Your Dll import unit unit MyDllProcs; interface function GetIntCalcResult(const IntVal: Integer); implementation function GetIntCalcResult(const IntVal: Integer); stdcall; external 'HNLib.dll'; end. // Your own app's code program Test; interface uses MyDllProcs; implementation function DoSomethingWithDll(const ValueToCalc: Integer): Integer; begin Result := GetIntCalcResult(ValueToCalc); end; begin WriteLn('DoSomethingWithDll returned ', DoSomethingWithDll(10)); ReadLn; end. |
请注意,当像这样静态链接DLL函数时,您的DLL必须在应用启动时可用,并且该函数必须包含在该DLL中;如果不是,则您的应用程序将无法加载。
此外,请注意,DLL中通常不能具有多个具有相同名称的功能,因为没有信息可用于确定加载完成时要加载哪个功能。每个名称应使用单独的唯一名称,否则加载可能会失败。