Why/when is __declspec( dllimport ) not needed?

__declspec(dllimport) is a client-side MSVC attribute that can be specified for imported code and data.

It isn’t required for code. It is an optimization; a client-side compiler hint that a function call isn’t direct but imported. The imported function pointer for a function named foo() will be __imp_foo. Without the hint, a thunk is created to load the address in __imp_foo and jump to it. With the hint the thunk is skipped and an indirect call through the IAT1 entry is generated i.e. the thunk is inlined. It is a time optimization, not space.

It’s required for data that’s imported from a DLL.

This blog post has the details.

1: Import Address Table of a program

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)