Why can't I return a char* string from C++ to C# in a Release build?

后端 未结 5 903
梦如初夏
梦如初夏 2021-01-31 10:07

I\'m attempting to call the following trivial C function from C#:

SIMPLEDLL_API const char* ReturnString()
{
    return \"Returning a static string!\";
}
         


        
5条回答
  •  时光取名叫无心
    2021-01-31 10:51

    The C++ compiler in Release mode is putting the constant into the data page, which is protected; attempting to hand this off to C# is causing problems. In Debug mode, the compiler isn't optimizing the constant into the data page, and so there's no protection problem.

提交回复
热议问题