What is the difference/relationship between "extern" and "__declspec(dllimport")? I found that sometimes it is necessary to use both of them, sometimes one is enough.
Am I right that:
Microsoft allows anyone to download Windows 10 for free and install it without a product key. It'll keep working for the foreseeable future, with only a few small cosmetic restrictions.
Assuming Microsoft sticks to the three-year update cycle Windows Central's Zac Bowden reports, Windows 12 would be released at some point in 2024.
Windows 11 is worth it for most people. It comes with a wide range of new features, performance improvements, and design changes. As the latest Windows OS, it usually gets more attention than Windows 10, too. There's not too much risk in upgrading to Windows 11, either.
Microsoft Windows, also called Windows and Windows OS, computer operating system (OS) developed by Microsoft Corporation to run personal computers (PCs). Featuring the first graphical user interface (GUI) for IBM-compatible PCs, the Windows OS soon dominated the PC market.
extern
means that the entity has external linkage, i.e. is visible outside its translation unit (C or CPP file). The implication of this is that a corresponding symbol will be placed in the object file, and it will hence also be visible if this object file is made part of a static library. However, extern
does not by itself imply that the symbol will also be visible once the object file is made part of a DLL.
__declspec(dllexport)
means that the symbol should be exported from a DLL (if it is indeed made part of a DLL). It is used when compiling the code that goes into the DLL.
__declspec(dllimport)
means that the symbol will be imported from a DLL. It is used when compiling the code that uses the DLL.
Because the same header file is usually used both when compiling the DLL itself as well as the client code that will use the DLL, it is customary to define a macro that resolves to __declspec(dllexport)
when compiling the DLL and __declspec(dllimport)
when compiling its client, like so:
#if COMPILING_THE_DLL #define DLLEXTERN __declspec(dllexport) #else #define DLLEXTERN __declspec(dllimport) #endif
To answer your specific questions:
extern
alone is sufficient for static libraries.extern
(see explanation here).extern
with a __declspec(dllimport)
(see explanation linked to above), but since you'll usually be using the same header file, you'll already have the extern
in there because it's needed when compiling the DLL.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