The blog for the ELF example only shows a number function. I needed a string function and struggled with it a bit because of the conversions. Here is the example code in case somebody needs it. This function formats a US-based phone number (MS Visual Studio 2017). Perhaps there is a more efficient way, but I haven't programmed in C++ for over 20 years. Feel free to enhance it for yourself.

#include <comutil.h>
#include <string>
#include <string.h>

#ifdef _DEBUG
#define new DEBUG_NEW

VARIANT __declspec(dllexport) FormatPhone(VARIANT sPhone)
	CComVariant vRes;
	char *p;
	static char ret[30];
	static char pAreaCode[4], pExchange[5], pNumber[5];


	// check argument type
	if (sPhone.vt != VT_BSTR) //VT_BSTR = string
		vRes.vt = VT_ERROR;
		vRes.scode = MAKE_HRESULT(1, FACILITY_ITF, 1);
		return vRes;

	p = _com_util::ConvertBSTRToString(sPhone.bstrVal);

	memset(ret, '\0', 30);

	// make sure the phone number is at least 10 characters
	if (strlen(p) >= 10)
		memset(pAreaCode, '\0', 4);
		memcpy(pAreaCode, &p[0], 3);
		strcpy_s(ret, "(");
		strcat_s(ret, pAreaCode);
		strcat_s(ret, ") ");

		memset(pExchange, '\0', 5);
		memcpy(pExchange, &p[3], 3);
		pExchange[3] = '-';
		strcat_s(ret, pExchange);

		memset(pNumber, '\0', 5);
		memcpy(pExchange, &p[6], 4);
		strcat_s(ret, pExchange);

	delete[] p;

	// return the phone number
	vRes = (LPCSTR)ret;
	return vRes;