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 init this VARIANT?

How to init this VARIANT?

Scheduled Pinned Locked Moved COM
c++tutorialquestion
6 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.
  • L Offline
    L Offline
    Lane Yu
    wrote on last edited by
    #1

    Now I'm trying to use IFolderCollection: struct __declspec(uuid("c7c3f5a3-88a3-11d0-abcb-00a0c90fffc0")) IFolderCollection : IDispatch { ... virtual HRESULT __stdcall get_Item ( VARIANT Key, struct IFolder * * ppfolder ) = 0; ... } In my code, I have got an interface of IFolderCollection. And I want to enumerate the sub folders: LONG nCount = qSubFolders->GetCount(); ... // for (INT nLoop = 1; nLoop <= nCount; nLoop++) { CComVariant vtKey(nLoop); vtKey.ChangeType(??????????); //Which type is "Key" type? CComPtr qFolder; qSubFolders->get_Item(vtKey, &qFolder); //Always fail! if (qFolder == NULL) { } ... In VB, I can write "Curfolder = Subfolders.Item(1)", but what about C++? -- modified at 23:27 Sunday 6th November, 2005

    D 1 Reply Last reply
    0
    • L Lane Yu

      Now I'm trying to use IFolderCollection: struct __declspec(uuid("c7c3f5a3-88a3-11d0-abcb-00a0c90fffc0")) IFolderCollection : IDispatch { ... virtual HRESULT __stdcall get_Item ( VARIANT Key, struct IFolder * * ppfolder ) = 0; ... } In my code, I have got an interface of IFolderCollection. And I want to enumerate the sub folders: LONG nCount = qSubFolders->GetCount(); ... // for (INT nLoop = 1; nLoop <= nCount; nLoop++) { CComVariant vtKey(nLoop); vtKey.ChangeType(??????????); //Which type is "Key" type? CComPtr qFolder; qSubFolders->get_Item(vtKey, &qFolder); //Always fail! if (qFolder == NULL) { } ... In VB, I can write "Curfolder = Subfolders.Item(1)", but what about C++? -- modified at 23:27 Sunday 6th November, 2005

      D Offline
      D Offline
      De Nardis Andrea
      wrote on last edited by
      #2

      Do you have access to the get_Item function? It is the only way to know the type. If I correctly undestand set Curfolder = Subfolders.Item(1) works, so it should work in C++ as well, with vtKey.ChangeType (VT_I2), vtKey.ChangeType (VT_I4), vtKey.ChangeType (VT_R4), or vtKey.ChangeType (VT_R8). You should also get the return code or some error info. Regards, Andrea

      L 1 Reply Last reply
      0
      • D De Nardis Andrea

        Do you have access to the get_Item function? It is the only way to know the type. If I correctly undestand set Curfolder = Subfolders.Item(1) works, so it should work in C++ as well, with vtKey.ChangeType (VT_I2), vtKey.ChangeType (VT_I4), vtKey.ChangeType (VT_R4), or vtKey.ChangeType (VT_R8). You should also get the return code or some error info. Regards, Andrea

        L Offline
        L Offline
        Lane Yu
        wrote on last edited by
        #3

        Thanks a lot. I'm sorry that I made a mistake. I haven't used VB for 2 years, so actually set Curfolder = Subfolders.Item(1) is only in my memory, it can NOT work. I found I could only visit this collection via "for each" in VB: For Each folderCur In subFolders Debug.Print folderCur.Path Next So what should I do in C++? Shall I use IFolderCollection::get__NewEnum(IUnknown * * ppenum) method? How to? Thanks. -- modified at 7:54 Monday 7th November, 2005

        D 1 Reply Last reply
        0
        • L Lane Yu

          Thanks a lot. I'm sorry that I made a mistake. I haven't used VB for 2 years, so actually set Curfolder = Subfolders.Item(1) is only in my memory, it can NOT work. I found I could only visit this collection via "for each" in VB: For Each folderCur In subFolders Debug.Print folderCur.Path Next So what should I do in C++? Shall I use IFolderCollection::get__NewEnum(IUnknown * * ppenum) method? How to? Thanks. -- modified at 7:54 Monday 7th November, 2005

          D Offline
          D Offline
          De Nardis Andrea
          wrote on last edited by
          #4

          I'm not an expert with Enum. I found some info on MSDN, look for IEnumXXXX and IEnumUnknown. In the C++ client you have to call Reset (), Next () in order to enumerate all the items. Look at ALCCollection sample, and keyword _Copy, CComEnumOnSTL, ICollectionOnSTLImpl, CAdapt, IEnumVARIANT, std::map, std::string, std::vector Hope this helps. Regards, Andrea

          L 1 Reply Last reply
          0
          • D De Nardis Andrea

            I'm not an expert with Enum. I found some info on MSDN, look for IEnumXXXX and IEnumUnknown. In the C++ client you have to call Reset (), Next () in order to enumerate all the items. Look at ALCCollection sample, and keyword _Copy, CComEnumOnSTL, ICollectionOnSTLImpl, CAdapt, IEnumVARIANT, std::map, std::string, std::vector Hope this helps. Regards, Andrea

            L Offline
            L Offline
            Lane Yu
            wrote on last edited by
            #5

            I have tried out one way to enumerate sub folders: ... CComPtr<IUnknown> qUnkown; qSubFolders->get__NewEnum(&qUnkown); if (qUnkown == NULL) { cout << "Fail to query _NewEnum!" << endl; return; } CComQIPtr<IEnumVARIANT> qEnumVT = qUnkown; if (qEnumVT == NULL) { cout << "Fail to query IEnumVARIANT!" << endl; return; } for (INT nLoop = 0; nLoop < nCount; nLoop++) { CComVariant vtEnum; qEnumVT->Next(1, &vtEnum, NULL); if (vtEnum.vt == VT_DISPATCH) { CComQIPtr<IFolder> qFolder = vtEnum.pdispVal; //Query IFolder vtEnum.pdispVal->Release(); if (qFolder != NULL) { CComBSTR bstrPath; qFolder->get_Path(&bstrPath); ... } } } However, how to use property "Item" in VC is still a question. Thank you.:) -- modified at 12:58 Monday 7th November, 2005

            D 1 Reply Last reply
            0
            • L Lane Yu

              I have tried out one way to enumerate sub folders: ... CComPtr<IUnknown> qUnkown; qSubFolders->get__NewEnum(&qUnkown); if (qUnkown == NULL) { cout << "Fail to query _NewEnum!" << endl; return; } CComQIPtr<IEnumVARIANT> qEnumVT = qUnkown; if (qEnumVT == NULL) { cout << "Fail to query IEnumVARIANT!" << endl; return; } for (INT nLoop = 0; nLoop < nCount; nLoop++) { CComVariant vtEnum; qEnumVT->Next(1, &vtEnum, NULL); if (vtEnum.vt == VT_DISPATCH) { CComQIPtr<IFolder> qFolder = vtEnum.pdispVal; //Query IFolder vtEnum.pdispVal->Release(); if (qFolder != NULL) { CComBSTR bstrPath; qFolder->get_Path(&bstrPath); ... } } } However, how to use property "Item" in VC is still a question. Thank you.:) -- modified at 12:58 Monday 7th November, 2005

              D Offline
              D Offline
              De Nardis Andrea
              wrote on last edited by
              #6

              In my opinion Item can be used "as is" and has little to do with enumeration, so I think the variang parameter can be a string instead of a number. This can be a particularity in your object.

              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