I found a way to get the function name without parsing the Excel Formula. In the official documentation, it is said that xlfRegister :
defines a hidden name which is the function text argument,
pxFunctionText, and which evaluates to the registration ID of the
function or command.
So we can use the registration ID to retrieve this hidden name. The following code does it, using xlfGetDef:
XLOPER12 xDLL, xRegId, xTypeNum, xFunctionName;
xTypeNum.xltype = xltypeInt;
xTypeNum.val.w = 3; // all names
Excel12(xlGetName, &xDLL, 0);// xDLL will be xltypeStr
Excel12(xlfRegisterId,&xRegId,2,(LPXLOPER12)&xDLL, TempStr12(_T(__FUNCTION__))); //xRegId will be XltypeNum
Excel12(xlfGetDef,&xFunctionName,3,(LPXLOPER12)(&xRegId),nullptr,(LPXLOPER12)&xTypeNum); // xFunctionName is the value we look for
Excel12(xlFree, nullptr, 1, (LPXLOPER12) &xDLL);
... //copy xFunctionName
Excel12(xlFree, nullptr, 1, (LPXLOPER12) &xFunctionName);
Note that in this code, the first argument (pxDefText ) of the call to xlfGetDef has type xltypeNum, this doesn't correspond to the offical documentation but it works (a hidden feature for a hidden name ?). This code can be optimised by calling only once xlGetName.
An alternative and probably more efficient way (without calling the Excel C API) would be to set a static std::map during registration (with key = name of the function as exported and value = pxFunctionText ), and to retrieve the value inside the function using the key : __FUNCTION__.