XLL+ Class Library

CXllApp::RetString

Return a string value to Excel.

[C++]
static const char* RetString(
   const char* psz
);
static const char* RetString(
   const std::string& s
);
static const char* RetString(
   const CString& str
);

Parameters

psz

The string to be returned.

s

A reference to the string to be returned.

str

A reference to the string to be returned.

Return value

A pointer to a string buffer that can be returned directly to Excel. The XLL+ run-time library will manage clean-up as required.

Remarks

For a string to be returned to Excel, it is necessary that its lifetime extend beyond that of the function from which it is called. One solution is to return a pointer to static storage, but this can be unwieldy and wasteful.

An easier technique is to return a string using RetString(), e.g.:

return CXllApp::RetString("Not a number");

Since this function is static, it is not necessary to use an instance of CXllApp to invoke it. It is not therefore necessary to fix the MFC CWinApp instance using the XLL_FIX_STATE macro: you can use code such as:

CString strResult;
strResult.Format("%s%s", apszItemName[i], (j > 1) ? "s" : "");
return CXllApp::RetString(strResult);

Requirements

Header: xllplus.h

See Also

CXllApp Class | CXllApp Methods