Use maxon::StringDecodings::Utf8()

  • std::string SceneParser::GetIDString(BaseList2D* node){
    Int memsize=0;
    const Char* mem;
    node->FindUniqueID(MAXON_CREATOR_ID, mem,  memsize);
    String ID_STR;
    std::string result=StringToStdString(ID_STR);
    return result;


    Hello. I have this function but when I try the debugger it breaks showing this

     DebugStop("Undefined encoding. Use maxon::StringDecodings::Utf8()");

    The Debugger Stops in this line "ID_STR.SetCString(mem,memsize);" which is a function of c4d_string.h from the framework.
    I understand what the error is but I am not finding the proper way to use "maxon::StringDecodings::Utf8()" so the function will work properly later. Is there any way I can fix this problem.
    Thank you in advance!

  • Global Moderator

    Hi Ogers, thanks for reaching us.

    With regard to your request, it's enough to pass the STRINGENCODING::UTF8 but I warmly suggest you to move from old string and use the maxon::String since the old implemetation just relies on the maxon::StringInterface::SetCString() method.

    Last but not least consider that you can initialize both a String or maxon::String directly by passing a Char* (see respectively here and here)

    For the sake of completeness, please find below a short snippet showing how to properly use SetCString()

    #include "maxon/stringencoding.h"
    maxon::Result<void> TestOnCString(BaseDocument *doc)
    	if (!doc)
    		return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION);
    	Int memsize = 0;
    	const Char* mem;
    	// try to find something meaningful
    	if (doc->FindUniqueID(MAXON_CREATOR_ID, mem,  memsize))
    		String c4dStr;
    		c4dStr.SetCString(mem, memsize, STRINGENCODING::UTF8);
    		DiagnosticOutput("c4dStr: @", maxon::String(c4dStr));
    	// add a more meaningful string
    	const Int mysize = 5;
    	const Char chars[mysize] = "MyID";
    	const Int myID = 12345;
    	doc->AddUniqueID(myID, chars, mysize);
    	if (doc->FindUniqueID(012345, mem,  memsize))
    		maxon::String maxonStr;
    		const maxon::StringDecodingRef& stringDecoding = maxon::StringDecodings::Utf8();
    		maxonStr.SetCString(mem, memsize, stringDecoding) iferr_return;
    		DiagnosticOutput("maxonStr: @", maxonStr);
    	return maxon::OK;

    Best, Riccardo

  • @r_gigante Thank you for your help. I used the maxon::String and it works fine.