There are many examples of how to call IDispatch::Invoke with a BSTR* parameter. I have this working with many other "SomeType*" parameter but no matter what I try, I either get HRESULT of Type Mismatch, E_OUTOFMEMORY or an access violation. It seems to me I am doing something wrong with memory but I am following the different examples I have found... As a side note, the final "[out] UINT puArgErr" argument is never filled with the argument index that is causing the problem. However, I know it is the 3rd argument of type BSTR (I have successfully called another method that takes the 2 previous arguments.)
VARIANTARG* v = new VARIANTARG[3];
//...Init my first 2 args
//Code omitted for initializing args 1 and 2 and wrapping everything up to call IDispatch->Invoke
//... Variation 1
VariantInit(v[2]);
BSTR val = SysAllocString(L"");
v[2].vt = VT_BSTR | BT_BYREF;
v[2].pbstrVal = &val;
//When I wrap everything up in the call to IDispatch::Invoke
//this yields a HRESULT of Type Mismatch
*
//...Variation 2
VariantInit(v[2]);
BSTR val = SysAllocString(L"");
v[2].vt = VT_BSTR | BT_BYREF;
v[2].bstrVal = val;
//When I wrap everything up in the call to IDispatch::Invoke
//this yields a HRESULT of E_OUTOFMEMORY
*
//...Variation 3
VariantInit(v[2]);
BSTR val = SysAllocString(L"RandomStringLargerThanTheMethodWillPlaceInTheOutParam");
v[2].vt = VT_BSTR | BT_BYREF;
v[2].bstrVal = val;
//When I wrap everything up in the call to IDispatch::Invoke
//this yields an access violation
*
//...Variation 4
VariantInit(v[2]);
BSTR val = 0;
v[2].vt = VT_BSTR | BT_BYREF;
v[2].bstrVal = val;
//When I wrap everything up in the call to IDispatch::Invoke
//this yields and HRESULT of 0x800706f4 A null reference pointer
//was passed to the stub.
I don't understand why when I am following other examples of BTR* parameters this is happening... Furthermore I have many other successful calls to IDispatch::Invoke but this BTR* has me ground to a halt.
DESPERATE, PLEASE HELP!
Addition:
IDL is: [id(0x00000171)] short GetCategory( short nIndx, short* nCat, BSTR* bszName);