How to set up a C++ function so that it can be used by p/invoke?

前端 未结 6 669
旧巷少年郎
旧巷少年郎 2020-12-30 13:01

Hopefully this is a brainlessly easy question, but it shows my lack of expertise with C++. I\'m a C# programmer, and I\'ve done extensive work with P/Invoke in the past wit

6条回答
  •  孤独总比滥情好
    2020-12-30 13:28

    You'll want to use extern "C" as well as __declspec(export), like so:

    extern "C" _declspec(dllexport)  bool TestFunc()
    {
        return true;
    }
    

    For full details, see MSDN on Marshalling Types.

提交回复
热议问题