How to extract data from VARIANT?
-
Hello, I am using a third party folder view control which has a method
GetSelectedFolder()
. The method returns aVARIANT
(VT_DISPATCH
). So:VARIANT varFolder = m_fvFolder.GetSelectedFolder(); if(varFolder.vt == VT_DISPATCH) { // What should be done here to extract the string containing the folder name? }
Thanks a lot in advance! Rgds, Nirav Doshi * Don't wish it was easier, wish you were better! *
-
Hello, I am using a third party folder view control which has a method
GetSelectedFolder()
. The method returns aVARIANT
(VT_DISPATCH
). So:VARIANT varFolder = m_fvFolder.GetSelectedFolder(); if(varFolder.vt == VT_DISPATCH) { // What should be done here to extract the string containing the folder name? }
Thanks a lot in advance! Rgds, Nirav Doshi * Don't wish it was easier, wish you were better! *
If it's returning a
VT_DISPATCH
, the contained value is an object reference to anIDispatch*
object. Not knowing how your third party folder view control works, I'd suggest looking upGetSelectedFolder()
in the docs. Chances are that the object is a "dual" object (vtable and dispatch interfaces) which implementsIFolder
something similar. You can acquire theIDispatch
interface using thepdispVal
member of VARIANT. Don't forget toVariantClear()
it when you are done or you will leak an object! For less error prone code, take a look at ATL's wrapper classCComVariant
. Similarly, if a VARIANT contains a VT_UNKNOWN, it holds a reference to anIUnknown*
object, which you'll have to query for a usable interface. It is accessed through thepunkVal
member. -- ...Coca Cola, sometimes war... -
If it's returning a
VT_DISPATCH
, the contained value is an object reference to anIDispatch*
object. Not knowing how your third party folder view control works, I'd suggest looking upGetSelectedFolder()
in the docs. Chances are that the object is a "dual" object (vtable and dispatch interfaces) which implementsIFolder
something similar. You can acquire theIDispatch
interface using thepdispVal
member of VARIANT. Don't forget toVariantClear()
it when you are done or you will leak an object! For less error prone code, take a look at ATL's wrapper classCComVariant
. Similarly, if a VARIANT contains a VT_UNKNOWN, it holds a reference to anIUnknown*
object, which you'll have to query for a usable interface. It is accessed through thepunkVal
member. -- ...Coca Cola, sometimes war...Jörgen, Thanks a lot for your reply! Jörgen Sigvardsson wrote: Not knowing how your third party folder view control works, I'd suggest looking up GetSelectedFolder() in the docs. The doc only explains this with reference to VB Samples! :( - So no use! Jörgen Sigvardsson wrote: Chances are that the object is a "dual" object (vtable and dispatch interfaces) which implements IFolder something similar. Doesn't seem to be that either! :( Jörgen Sigvardsson wrote: You can acquire the IDispatch interface using the pdispVal member of VARIANT Is it something like:
IDispatch *pIDisp = varFolder.pdispVal;
Had tried this earlier, but what further? :confused: Thanks, Rgds, Nirav Doshi * Don't wish it was easier, wish you were better! *
-
Jörgen, Thanks a lot for your reply! Jörgen Sigvardsson wrote: Not knowing how your third party folder view control works, I'd suggest looking up GetSelectedFolder() in the docs. The doc only explains this with reference to VB Samples! :( - So no use! Jörgen Sigvardsson wrote: Chances are that the object is a "dual" object (vtable and dispatch interfaces) which implements IFolder something similar. Doesn't seem to be that either! :( Jörgen Sigvardsson wrote: You can acquire the IDispatch interface using the pdispVal member of VARIANT Is it something like:
IDispatch *pIDisp = varFolder.pdispVal;
Had tried this earlier, but what further? :confused: Thanks, Rgds, Nirav Doshi * Don't wish it was easier, wish you were better! *
Nirav Doshi wrote: Had tried this earlier, but what further? I can't help you with that, I'm afraid. You need a description of the interface(s) which the returned object exposes. Nirav Doshi wrote: The doc only explains this with reference to VB Samples! That may be of good use. You could access the object using the dispatch interface using a dispatch driver such as this one[^]. Then you'd have to do something like:
XYDispDriver disp;
disp.Attach(varFolder.pdispVal);
::VariantClear(&varFolder); // Just to remind you of releasing this one ;)
VARIANT* var = disp.GetProperty(_T("PropertyName"));
UseVariant(*var);
var = disp.InvokeMethod(_T("MethodName"), arg1, arg2);
UseVariant(*var);Please read the article for more information on how the XYDispDriver works as I'm not the author of it. And also look at the VB samples to learn about the properties and methods which can be used. Happy coding! -- ...Coca Cola, sometimes war...
-
Nirav Doshi wrote: Had tried this earlier, but what further? I can't help you with that, I'm afraid. You need a description of the interface(s) which the returned object exposes. Nirav Doshi wrote: The doc only explains this with reference to VB Samples! That may be of good use. You could access the object using the dispatch interface using a dispatch driver such as this one[^]. Then you'd have to do something like:
XYDispDriver disp;
disp.Attach(varFolder.pdispVal);
::VariantClear(&varFolder); // Just to remind you of releasing this one ;)
VARIANT* var = disp.GetProperty(_T("PropertyName"));
UseVariant(*var);
var = disp.InvokeMethod(_T("MethodName"), arg1, arg2);
UseVariant(*var);Please read the article for more information on how the XYDispDriver works as I'm not the author of it. And also look at the VB samples to learn about the properties and methods which can be used. Happy coding! -- ...Coca Cola, sometimes war...
Hello Jörgen, Thank you very much for your reply! I will explore more on this! Atleast now I have some pointers to start with... :) Rgds, Nirav * Don't wish it was easier, wish you were better! *