Using vswprintf( ... ) to create wchar_t* with variable argument list
The code you have written is fine, apart from three small issues:

You need to check that format isn't null before calling vswprintf otherwise it crashes.
There seems to be the potential for memory leaking, you are assuming the caller will always release the memory.  It would return a std::wstring instead, no need to new the buffer and it is &quot;automatically&quot; released.
Check the results of vswprintf_s() it will almost never fail, but when it does you'll be trying to track down what went wrong for days. :)

This is my version:
// the caller will free the memory
std::wstring getMessage(const wchar_t* format, ...)
{
    std::wstring output;                                            // function return value.
    if (format != nullptr)
    {
        va_list args;
        va_start(args, format);
        const auto size = vswprintf(nullptr, 0, format, args);      // get the size of the final string
        if (size &gt; 0)                                               // If the above call worked
        {   
            const auto buffSize = 1 + size;
            output.reserve(buffSize);                               // create the buffer
            if (vswprintf_s(output.data, buffSize, format, args) &lt; 0)// create the string
            {
                output.clear();                                     // Empty the string if there is a problem
            }
        }
        va_end(args);
    }
    return output;
}