When I export a procedure ha
from a library multiple times:
library hahaha;
procedure ha;
begin
Writeln('ha')
end;
exports
ha, ha, ha;
end.
Delphi neatly creates a .dll with three procedures:
I was surprised that the ambiguous call GetProcAddress(LoadLibrary('hahaha.dll'), 'ha')
doesn't fail.
That made me wonder: is there a case where this is useful?
One place where this is useful is when you wish to export the function multiple times with different names. For instance, if we were attempting to re-implement user32
in Delphi we might have exports like this:
exports
SetWindowTextA,
SetWindowTextA name 'SetWindowText';
In your case though you are exporting the same function multiple times with the same name and different ordinal values. Why would you want to do that? I can see no good reason for wanting to do that. However, why should the compiler stop you from doing this? It would take effort from the compiler developer to do so, and what would be gained?
My guess therefore, is that the compiler developer did not implement a block on multiple exports with the same name because either:
As for what happens when you call GetProcAddress
with a function name that has been exported multiple times, the system will return the first exported function whose name matches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With