convert selection variant idispatch to something useful

L

Lynn McGuire

I have a C++ app that I am converting from using DDE to OLE Automation
to talk with Excel. Does anyone know how to convert a "selection" Variant
of type VT_DISPATCH to something useful like a char string ?

Thanks,
Lynn McGuire
 
A

Akihito Yamashiro

Hi.

Could you tell me more about that?
What inconvenience do you feel when you use VT_DISPATCH?
 
L

Lynn McGuire

Could you tell me more about that?
What inconvenience do you feel when you use VT_DISPATCH?

I have no idea how to convert the variant to char * strings:

IDispatch *pDocApp;
{
VARIANT result;
VariantInit ( & result);
OLEMethod (DISPATCH_PROPERTYGET, & result, pXlApp, L"Application", 0);
pDocApp = result.pdispVal;
}
IDispatch *pXlSelection;
{
VARIANT result;
VariantInit ( & result);
OLEMethod (DISPATCH_PROPERTYGET, & result, pDocApp, L"Selection", 0);
pXlSelection = result.pdispVal;
if (result.vt == VT_DISPATCH)
{
IDispatch *pDisp = result.pdispVal;
// how to convert this idispatch pointer to char * strings now ???
}
}

Thanks,
Lynn
 
L

Lynn McGuire

I have no idea how to convert the variant to char * strings:

Figured it out:

{
VARIANT result;
VariantInit ( & result);
OLEMethod (DISPATCH_PROPERTYGET, & result, pXlApplication, L"Selection", 0);
if (result.vt == VT_DISPATCH)
{
IDispatch *pDisp = result.pdispVal;
// this will get the contents of the selected cell
// VariantInit ( & result);
// OLEMethod (DISPATCH_PROPERTYGET, & result, pDisp, L"Value", 0);
// int res_value = result.vt;
// this will get the address of the selected cell
VariantInit ( & result);
OLEMethod (DISPATCH_PROPERTYGET, & result, pDisp, L"Address", 0);
if (result.vt == VT_BSTR)
selection = _bstr_t (result.bstrVal);
pDisp -> Release ();
}
}

Thanks,
Lynn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top