Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. How to extract data from VARIANT?

How to extract data from VARIANT?

Scheduled Pinned Locked Moved COM
tutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nirav Doshi
    wrote on last edited by
    #1

    Hello, I am using a third party folder view control which has a method GetSelectedFolder(). The method returns a VARIANT (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! *

    J 1 Reply Last reply
    0
    • N Nirav Doshi

      Hello, I am using a third party folder view control which has a method GetSelectedFolder(). The method returns a VARIANT (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! *

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      If it's returning a VT_DISPATCH, the contained value is an object reference to an IDispatch* object. Not knowing how your third party folder view control works, I'd suggest looking up GetSelectedFolder() in the docs. Chances are that the object is a "dual" object (vtable and dispatch interfaces) which implements IFolder something similar. You can acquire the IDispatch interface using the pdispVal member of VARIANT. Don't forget to VariantClear() it when you are done or you will leak an object! For less error prone code, take a look at ATL's wrapper class CComVariant. Similarly, if a VARIANT contains a VT_UNKNOWN, it holds a reference to an IUnknown* object, which you'll have to query for a usable interface. It is accessed through the punkVal member. -- ...Coca Cola, sometimes war...

      N 1 Reply Last reply
      0
      • J Jorgen Sigvardsson

        If it's returning a VT_DISPATCH, the contained value is an object reference to an IDispatch* object. Not knowing how your third party folder view control works, I'd suggest looking up GetSelectedFolder() in the docs. Chances are that the object is a "dual" object (vtable and dispatch interfaces) which implements IFolder something similar. You can acquire the IDispatch interface using the pdispVal member of VARIANT. Don't forget to VariantClear() it when you are done or you will leak an object! For less error prone code, take a look at ATL's wrapper class CComVariant. Similarly, if a VARIANT contains a VT_UNKNOWN, it holds a reference to an IUnknown* object, which you'll have to query for a usable interface. It is accessed through the punkVal member. -- ...Coca Cola, sometimes war...

        N Offline
        N Offline
        Nirav Doshi
        wrote on last edited by
        #3

        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 1 Reply Last reply
        0
        • N Nirav Doshi

          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 Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          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...

          N 1 Reply Last reply
          0
          • J Jorgen Sigvardsson

            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...

            N Offline
            N Offline
            Nirav Doshi
            wrote on last edited by
            #5

            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! *

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups