Exporting Class Methods and Functions in Microsoft Visual Studio
- Updated2024-11-26
- 1 minute(s) read
Exporting Class Methods and Functions in Microsoft Visual Studio
Use the C/C++ DLL Adapter to call functions and static class methods in DLLs. The C/C++ DLL Adapter obtains a list of available functions and methods from the list of exports contained in the DLL file. In addition, the C/C++ DLL Adapter determines parameter type information by reading a type library or by examining the decorated names the Microsoft Visual Studio compiler generates.
To ensure that the functions and methods are available to the C/C++ DLL Adapter, follow these rules when defining the functions and classes:
- Use __declspec(dllexport) to export the function or method. You can export an entire C++ class by placing the __declspec(dllexport) before the class name, or you can export a single method by placing __declspec(dllexport) before the method name.
- Make class methods static and public. The C/C++ DLL Adapter does not allow you to call public non-static methods.
- Use only types the C/C++ DLL Adapter recognizes.
- Avoid using a .DEF file to export symbols. Using a .DEF file prevents the C/C++ DLL Adapter from obtaining type information for function and method parameters.
- Avoid using the extern "C" syntax to export symbols. The extern "C" syntax prevents the C/C++ DLL Adapter from obtaining type information for function and method parameters.
Refer to the following examples for more information:
Example 1
class __declspec(dllexport) ClassName {
public: static void MethodName(void);
};
Example 2
class ClassName {
public: static void __declspec(dllexport) MethodName(void);
};
Example 3
void __declspec(dllexport) Function(void);