What is the difference between calling an Win API in following codes
Code #1:
uses
Winapi.ActiveX;
procedure Foo();
var
pv :Pointer;
begin
CoTaskMemFree(pv);
end;
Code #2:
procedure CoTaskMemFree(
pv: Pointer
); stdcall; external 'ole32.dll';
procedure Foo();
var
pv :Pointer;
begin
CoTaskMemFree(pv);
end;
I noticed the executable file size of Code 1 (161,792 bytes) is bigger than executable file of code 2 (23,552 bytes). i think that because of Code 1 will also compile the following units.
unit Winapi.ActiveX;
uses Winapi.Messages, System.Types, Winapi.Windows;
The difference in size is for the reasons that you outline. When you use a unit, your executable will contain code from that unit, and any dependent units. There are various options that you can use to reduce the impact, but invariably your executable size will increase when you use a unit that was not previously used.
procedure CoTaskMemFree(pv: Pointer); stdcall; external 'ole32.dll';
It is perfectly reasonable for you to define this yourself, in this manner, and so avoid using Winapi.ActiveX
. In fact, it would be far better if the Delphi RTL was more granular to support such uses. It's quite natural to wish to access the COM heap allocation routines, but nothing more.
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