See the question and my original answer on StackOverflow

If you want to use the VARIANT raw structure, you can code it like this:

VARIANT v;
VariantInit(&v);
pApp->AddRef();
v.pdispVal = pApp;
v.vt = VT_DISPATCH;
...
// later on, some code (this code or another code) will/should call this
VariantClear(&v); // implicitely calls pdispVal->Release();

Or, if you're using the Visual Studio development environment, then you can just use the _variant_t or CComVariant (ATL) smart wrappers which I recommend. In this case, you can just call it like this:

IDispatch *pApp = ...

// both wrappers will call appropriate methods
// and will release what must be, when destroyed
CComVariant cv = pApp;

// or

_variant_t vt = pApp;

PS: don't use both wrapper classes, make your choice. If a project uses ATL, I uses CComVariant, otherwise _variant_t, for example.