extern(Windows, "user32.dll")

Benjamin Thaut via Digitalmars-d digitalmars-d at puremagic.com
Sun Feb 1 02:40:08 PST 2015


Am 01.02.2015 um 11:26 schrieb Vladimir Panteleev:
> The Delphi programming language allows specifying the DLL name right on
> the declaration of extern symbols:
>
> function GetVersion: DWORD; stdcall; external 'kernel32.dll';
>
> I would like to suggest adding something similar to D:
>
> extern(Windows, "kernel32.dll") DWORD GetVersion();
>
> Rationale:
>
> This absolves the need for import libraries.
>
> * Import libraries are a major and unnecessary pain in the neck when
> using DLLs of any kind.
>
> * Import libraries may need conversion from COFF format to OMF format
> with a tool which is not included with D (coffimplib).
>
> * Import libraries can *sometimes* be created from the DLL using implib,
> but this does not always work, depending on the calling convention and
> its mangling.
>
> * Name mangling mismatches are difficult to diagnose.
>
> * Import libraries cannot be used with tools such as "rdmd", except via
> pragma(lib).
>
> Any thoughts? DIP or not?

Please no. Import libraries are the way it was designed and it should be 
used that way. I'm currently implementing D-Dll support for Windows with 
dmd and without import libraries it will never work.

Also what you are proposing could easily be implemented by a library. E.g.

@dllimport("kernel32.dll") extern(Windows) DWORD GetVersion();
mixin DllImportFunctions;

Where DllImportFunctions would iterate over all symbols in the module, 
look for the UDA dllimport and then attemp to load the Dll and import 
the function.

Kind Regards
Benjamin Thaut



More information about the Digitalmars-d mailing list