I'm developing a DLL that connects C++ with C# code, using C++/CLI in Visual Studio 2017. For the project I enabled the complier option '/clr' in Project -> Properties -> General
. I created a String^
variable that for which I would like to read its length, yet I am unable to do so, since the IntelliSense cannot find the property Length
, while most of the other System::String
functions are available, like Clone, Compare, CompareOrdinal
etc.
In the pseudo-code example below, I would like to copy a String
to a buffer, but truncate if its length exceeds some limit.
void copyToBuffer(String^ message, char* f_buffer)
{
if(message->Length > some limit)
truncate...
copy to buffer...
}
The compilation fails because the compiler throws an error of class "System::String" has no member "Length"
, even though I can easily navigate to the Length
property in the Object Browser.
Length is listed in the Object Browser
What's missing?
Change the project build property from "/permissive-" to "/permissive" After I did this in a test, the Length property appears useful.