5.8.1 Declaring Service Functions
When declaring a service function for a C++ compiler, you must declare it to have “C” linkage using extern “C”
. Specify the function prototype as follows:
#ifdef __cplusplus
extern "C"
#endif
MYSERVICE(TPSVCINFO *tpsvcinfo)
By declaring the name of your service with “C” linkage, you ensure that the C++ compiler will not modify the name. Many C++ compilers change the function name to include type information for the parameters and function return.
This declaration also allows you to:
- Link both C and C++ service routines into a single server without indicating the type of each routine.
- Use dynamic service advertisement, which requires accessing the symbol table of the executable to find the function name.
Parent topic: Using a C++ Compiler