February 3, 2017
by Ákos Somorjai
modified at May 19, 2017

Hello, world!

Here comes every programmer’s favourite example: “Hello, world!” – API style!

GSErrCode Do_CreateHelloWord (void)
{
    const char      hwText[] = { "Hello, API world!" };
    const size_t    hwLen  = strlen (hwText) + 1;

    return ACAPI_CallUndoableCommand (hwText,
        [&] () -> GSErrCode {
            API_Element     element;
            API_ElementMemo memo;
            GSErrCode       err = NoError;

            BNClear (element);
            BNClear (memo);

            element.header.typeID = API_TextID;
            ACAPI_Element_GetDefaults (&element, nullptr);

            // set up text encoding
            element.text.charCode = CC_UTF8;
            // place at (2, 2) on floor plan
            element.text.loc.x = element.text.loc.y = 2;
            // add our favourite text
            memo.textContent = reinterpret_cast<char**> (BMhAll (hwLen));
            CHTruncate (hwText, *memo.textContent, hwLen);

            // create the text element 
            err = ACAPI_Element_Create (&element, &memo);

            // clean up
            ACAPI_DisposeElemMemoHdls (&memo);
            return err;
        });
} // Do_CreateHelloWord