Search code examples
c++dllexportcritical-section

Can I export a Windows CRITICAL_SECTION from a DLL?


I hovered over CRITICAL_SECTION in VSCode and the tooltip reads:

typedef RTL_CRITICAL_SECTION CRITICAL_SECTION 
typedef struct __unnamed_struct_13a13_1 CRITICAL_SECTION

I am not sure how exporting structs work. Can I do this?

extern "C" __declspec(dllexport) CRITICAL_SECTION myCritSect;

Solution

  • I do not see why it should not work, but I would rather use a pointer to critical section returned by a function. That must definitely work.

    extern "C" __declspec(dllexport) LPCRITICAL_SECTION GetProtector();