Search code examples
c++autocad-pluginobjectarx

AutoCAD ObjectARX c++ What is the syntax to convert a AcString to a std::string value?


I am very new to ObjectARX and c++ and I hope you can help.

I am using AutoCAD 2023 and Visual Studio 2019.

I have successfully compiled and loaded my c++ function as ARX and called from within AutoLISP.

(myfunc "Hello World")

I have managed to get the value of Lacstring_parameter_passed_to_myfunc "Hello World"

What syntax do I use to get the value of Lacstring_parameter_passed_to_myfunc as a std::string ???

        static int myfunc(struct resbuf* rb)
        {
            AcString Lacstring_parameter_passed_to_myfunc;
            if (rb->restype == RTSTR) {
        Lacstring_parameter_passed_to_myfunc = rb->resval.rstring;
            }

    std::string my_string_parameter_passed_to_myfunc = "????????" 

        // What is the syntax to convert a AcString to a std::string value??

        }


Solution

  • Try this:

    AcString base = _T("testżźę");
    CT2CA pszConvertedAnsiString(base);
    std::string strStd(pszConvertedAnsiString);