I'm just looking for a simple, concise explanation of the difference between these two. MSDN doesn't go into a hell of a lot of detail here.
相关问题
- How to know full paths to DLL's from .csproj f
- how to call a C++ dll from C# windows application
- efficiently calling unmanaged method taking unmana
- How to reimport module with ES6 import
- Why is my COM factory never released during the pr
相关文章
- vs2017wpf项目引用dll的路径不正确的问题
- Determine if an executable (or library) is 32 -or
- C++: Callback typedefs with __stdcall in MSVC
- Are resource files compiled as UNICODE or ANSI cod
- Java “static import” vs. “import static” in Java 8
- Is it possible to check whether you are building f
- Which VC++ redistributable package to choose (x86
- How do I add a Python import path permanently?
__declspec( dllexport )
- The class or function so tagged will be exported from the DLL it is built in. If you're building a DLL and you want an API, you'll need to use this or a separate .DEF file that defines the exports (MSDN). This is handy because it keeps the definition in one place, but the .DEF file provides more options.__declspec( dllimport )
- The class or function so tagged will be imported from a DLL. This is not actually required - you need an import library anyway to make the linker happy. But when properly marked withdllimport
, the compiler and linker have enough information to optimize the call; without it, you get normal static linking to a stub function in the import library, which adds unnecessary indirection. ONT1 ONT2__declspec(dllexport)
tells the linker that you want this object to be made available for other DLL's to import. It is used when creating a DLL that others can link to.__declspec(dllimport)
imports the implementation from a DLL so your application can use it.I'm only a novice C/C++ developer, so perhaps someone's got a better explanation than I.
Dllexport is used to mark a function as exported. You implement the function in your DLL and export it so it becomes available to anyone using your DLL.
Dllimport is the opposite: it marks a function as being imported from a DLL. In this case you only declare the function's signature and link your code with the library.
Two different use cases:
1) You are defining a class implementation within a dll. You want another program to use the class. Here you use dllexport as you are creating a class that you wish the dll to expose.
2) You are using a function provided by a dll. You include a header supplied with the dll. Here the header uses dllimport to bring in the implementation to be used by the current program.
Often the same header file is used in both cases and a macro defined. The build configuration defines the macro to be import or export depending which it needs.