Question

I 'm working on a project (VS 2012 solution) including joystic.cpp. Project has been created as DLL, in order to be able to call library from another project. The application receives immediate joypad data in exclusive mode via a dialog timer, displaying them in a dialog box.

I edited the resource.h file with macro:

#ifdef LIBRARY_EXPORTS
#    define LIBRARY_API __declspec(dllexport)
#else
#    define LIBRARY_API __declspec(dllimport)
#endif

in order to be able to export functions by ordering:

LIBRARY_API function();

However, should I export all functions of the program, or not?

Was it helpful?

Solution

Should I export all functions of the program, or not?

Generally when designing the interface to a library, you should export just the functions that are needed by consumers of the library.

If you exported every function then you would need to document every function. However, many functions may not be needed by library consumers. Many functions will be private to the implementation of the library.

What's more, by exporting all functions you would be making future development of the library more difficult. What if you wanted to change the interface to one of these private functions that you exported? You would have to either introduce another function with a different name, or use the existing name and so break binary backwards compatibility. Neither of these options is particularly appealing.

In essence, the larger the surface area of your library's public interface, the larger your maintenance task. So you generally aim to provide the smallest possible public interface that provides the required functionality to library consumers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top