From the example you give us, you can not pass the wchar_t* string as an function parameter which you want to invoke in AutoWrap, you need package it as a BSTR type, which has a different memory layout that that of wchar_t* string, so it will cause crash.
The correct way is in the example you give us:
VARIANT x;
x.vt = VT_BSTR;
x.bstrVal = SysAllocString(L"All-In-One Code Framework");
AutoWrap(DISPATCH_PROPERTYPUT, NULL, pTxtRange, L"Text", 1, x);
VariantClear(&x);