[fpc-pascal] Cannot find entry point of a routine inside a windows 64 dll

Sven Barth pascaldragon at googlemail.com
Sun Dec 17 21:11:44 CET 2017


On 15.12.2017 16:10, Dennis wrote:
>>
>> Okay, that explains things a bit more.
>>
>> May I ask you to provide a small example consisting of program and
>> library (source only) that works in 32-bit, but fails in 64-bit? Try
>> way I can check myself what is going on as I have a Delphi starter on
>> my 64-bit Windows as well. Though it will be the weekend till I'll
>> have the time to look at it.
> 
> Sven,
> 
> Attached is a zipped file containing the Caller program and Callee dll.
> Both Compiled ok in windows 32 but when running Caller.exe, it reported
> the error.
> 
> Thanks a lot.

There were two adjustments I had to do to make it work correctly:

- add {$mode objfpc} to Caller.lpr as I was compiling from the commandline
- adjust the casing of ReOpenExcelWorkBook so that it matched the one
from ReopenExcelWorkBook (these are case sensitive!)

With these changes it worked without problem on win64.

That said you might want to apply the following two points to your
library interface:
- export/import functions/procedures using explicit names (extending
"external LibName" to "external LibName name 'ProcName'" for each
routine to import and adding "name 'ProcName'" for each routine in the
exports section) to be sure that no name mangling interferes here
- add an explicit calling convention to each routine for import and
export (you could use "register", the default calling convention since
Delphi and FPC *should* be compatible here, but "stdcall" would be my
suggestion to be on the save side)

Additionally you can check for any discrepancies using the Dependency
Walker ( http://www.dependencywalker.com/ ). Just open the executable
while the library is located in the same directory and you can see which
routines mismatch.

Regards,
Sven



More information about the fpc-pascal mailing list