What does CV_EXPORTS_W mean?

Recently, I am trying to figure out the source code of the calcOpticalFlowPyrLK function in the OpenCV library. When I searched for a definition, I found a macro called "CV_EXPORTS_W". Does anyone know what that means?

+4
source share
2 answers

CV_EXPORTS_W defined in the modules / core / include / opencv 2 / core / types_c.h as an alias for CV_EXPORTS , and in the same file CV_EXPORTS is defined as :

 #if (defined WIN32 || defined _WIN32 || defined WINCE) && defined CVAPI_EXPORTS # define CV_EXPORTS __declspec(dllexport) #else # define CV_EXPORTS #endif 

In other words, it is an alias for __declspec(dllexport) on a Windows platform where CVAPI_EXPORTS defined, otherwise it is empty.

+6
source

You can export data, functions, classes, or functions of class members from a DLL using the __declspec (dllexport) keyword.

Microsoft introduced __export in the 16-bit version of the Visual C ++ compiler so that the compiler can automatically generate export names and put them in a .lib file. This .lib file can be used in the same way as a static .lib to communicate with a DLL.

In newer versions of the compiler, you can export data, functions, classes, or functions of class members from a DLL using the __declspec (dllexport) keyword. __declspec (dllexport) adds an export directive to the object file, so you do not need to use a .def file.

This convenience is most obvious when trying to export decorated C ++ function names. Since there is no standard specification for decorating a name, the name of the exported function may change between versions of the compiler. If you use __declspec (dllexport), recompiling the DLL and dependent .exe files is only necessary to account for any changes to the naming convention.

Many export directives, such as ordinals, NONAME, and PRIVATE, can only be made in a .def file, and there is no way to specify these attributes without a .def file. However, using __declspec (dllexport) in addition to using a .def file does not cause build errors.

To export functions, the __declspec (dllexport) keyword should appear to the left of the call-convention keyword if a keyword is specified. For instance:

__ declspec (dllexport) void __cdecl Function1 (void);

To export all common data members and member functions in a class, the keyword should appear to the left of the class name as follows:

class __declspec (dllexport) CExampleExport: public CObject {... class definition ...};

Notenote

__ declspec (dllexport) cannot be applied to a function using the __clrcall calling convention.

When you create your DLL, a header file is usually created that contains the prototypes of the functions and / or classes that you export, and add __declspec (dllexport) to the declarations in the header file. To make your code more readable, define a macro for __declspec (dllexport) and use a macro with each exported character:

define DllExport __declspec (dllexport)

__ declspec (dllexport) stores function names in the DLL export table. If you want to optimize the size of the table, see "Exporting Functions from the DLL" using "Corrections by Name".

+2
source

All Articles