How to init this VARIANT?
-
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
-
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
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 -
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, AndreaThanks 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 useIFolderCollection::get__NewEnum(IUnknown * * ppenum)
method? How to? Thanks. -- modified at 7:54 Monday 7th November, 2005 -
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 useIFolderCollection::get__NewEnum(IUnknown * * ppenum)
method? How to? Thanks. -- modified at 7:54 Monday 7th November, 2005I'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
-
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
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 -
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, 2005In 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.