Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: Mon, 5 Jun 2006 21:37:42 +0200,    group: microsoft.public.platformsdk.com_ole        back       


IEnumString next method question   
Hi Everybody,  i am stuck again with a newbie problem, but it's less 
important since i have now a workaround, but it would be nice to have an 
answer...

here is the problem, in my previous post, i exposed the IDL for the iriver 
interface, one of  the methods is dir :

        [id(0x00000001), helpstring("method dir")]
        HRESULT dir(IUnknown** ppenum);

I figured out that the object supports IEnumString with help of 
QueryInterface.
Now i try to use the next method to fetch the first element of the 
enumerator :

 ULONG numreq;
 ULONG numret;
 wchar_t* element = 0;

 hr = pUnkTest->QueryInterface(IID_IEnumString,(void **) &pTest);

 if(SUCCEEDED(hr)) {
          numreq = 1;
          pTest->Next(numreq,&element,&numret);
           wprintf(L"result: %u %s",numret,element);
            }

It doesn't work as expected, i always get S_FAILED for hr and 0 for numret.
I informed myself a bit and it seems that the second parameter is a pointer 
to a pointer of wide string (LPOLESTR) that is identical to wchar_t, 
However, since the function can return multiple elements if numreq > 1, the 
supplied second parameter, should be an array of pointers to wide strings, 
right ??


Thank you again in advance.
date: Mon, 5 Jun 2006 21:37:42 +0200   author:   Rod

Re: IEnumString next method question   
Rod  wrote:
> hr = pUnkTest->QueryInterface(IID_IEnumString,(void **) &pTest);
>
> if(SUCCEEDED(hr)) {
>          numreq = 1;
>          pTest->Next(numreq,&element,&numret);
>           wprintf(L"result: %u %s",numret,element);
>            }
>
> It doesn't work as expected, i always get S_FAILED for hr and 0 for
> numret.

This is normal. It just means the collection is empty - there's nothing 
to enumerate.

> I informed myself a bit and it seems that the second
> parameter is a pointer to a pointer of wide string (LPOLESTR) that is
> identical to wchar_t, However, since the function can return multiple
> elements if numreq > 1, the supplied second parameter, should be an
> array of pointers to wide strings, right ??

Well, yes. But the function would never return more elements than you 
ask for (as specified by the first parameter), and since you always ask 
for one element, the issue is somewhat moot.
-- 
With best wishes,
    Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not 
necessarily a good idea. It is hard to be sure where they are going to 
land, and it could be dangerous sitting under them as they fly 
overhead. -- RFC 1925
date: Mon, 5 Jun 2006 15:50:13 -0400   author:   Igor Tandetnik

Re: IEnumString next method question   
"Rod"  wrote in message 
news:%237zhFeNiGHA.2268@TK2MSFTNGP04.phx.gbl...
> Hi Everybody,  i am stuck again with a newbie problem, but it's less 
> important since i have now a workaround, but it would be nice to have an 
> answer...
>
> here is the problem, in my previous post, i exposed the IDL for the iriver 
> interface, one of  the methods is dir :
>
>        [id(0x00000001), helpstring("method dir")]
>        HRESULT dir(IUnknown** ppenum);
>
> I figured out that the object supports IEnumString with help of 
> QueryInterface.
> Now i try to use the next method to fetch the first element of the 
> enumerator :
>
> ULONG numreq;
> ULONG numret;
> wchar_t* element = 0;
>
> hr = pUnkTest->QueryInterface(IID_IEnumString,(void **) &pTest);
>
> if(SUCCEEDED(hr)) {
>          numreq = 1;
>          pTest->Next(numreq,&element,&numret);
>           wprintf(L"result: %u %s",numret,element);
>            }
>
> It doesn't work as expected, i always get S_FAILED for hr and 0 for 
> numret.
> I informed myself a bit and it seems that the second parameter is a 
> pointer to a pointer of wide string (LPOLESTR) that is identical to 
> wchar_t, However, since the function can return multiple elements if 
> numreq > 1, the supplied second parameter, should be an array of pointers 
> to wide strings, right ??

That's correct.

You need to initialize numreq. The first parameter specifies how many 
strings you want returned. Because it contains a garbage value, the Next() 
method is returning S_FALSE. (There is no such HRESULT as S_FAILED).

Brian
date: Mon, 5 Jun 2006 12:52:34 -0700   author:   Brian Muth

Re: IEnumString next method question   
Oops, I didn't see that you set it to one. In this case, you will only get 
one string back.

Brian
date: Mon, 5 Jun 2006 12:54:16 -0700   author:   Brian Muth

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us