Click here to Skip to main content
15,888,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
static __declspec(dllexport) double Add(double a, double b);

What I have tried:

I have tried to implement both static and dynamic link library in a same program
Posted
Updated 9-Aug-16 22:58pm
Comments
CPallini 10-Aug-16 2:31am    
"I have tried to implement both static and dynamic link library in a same program"
Sorry?

It instructs the linker that it should export the function Add when building a DLL so that it can be called by other programs or DLLs when loading the DLL containing that function.

See also dllexport, dllimport[^] in the MSDN.

The import attribute is the opposite:
It tells the linker that the function is not located in the program or DLL that is actually build but contained in another DLL.

When buidling a DLL, you can use the export attribute to avoid creating a module-definition file. The import attribute can then be used in the header file for that DLL to be included when building an application or DLL that loads the DLL.
 
Share this answer
 
Comments
Member 12678496 10-Aug-16 3:16am    
Thank u
With Windows DLLs, there is a specific distinction between __declspec(dllexport) vs __declspec(dllimport), dllexport should be used when compiling the DLL, dllimport should be used when compiling programs that link to this DLL. The standard way of defining this would be with a macro.

The following is the visual studio example
// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the DLL_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// DLL_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef DLL_EXPORTS
#define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900