Problems using WNetOpenEnums()

Hi, I'm trying to use WNetOpenEnums to get a list of network shares, and eventually build a network tree...and I'm running into some real fustration trying to get it to work.  When I call the function, I get an unhandled exception error in mpr.dll.  I can't figure out what I'm doing wrong in the call, and I've been over the MSDN entries about a hundred times.  Below is the code that's calling the function.  Please let me know if you have any suggestions.

int MSShare::Dir(NetEntity *loc, NetEntity *NEbuff, int buffsize) {

      LPHANDLE hEnum;
      
      LPNETRESOURCE nr,NRbuff;
      
      DWORD res;
      unsigned long int cbBuff,cCount,counter,Tmp_Buffsize;

      Tmp_Buffsize=buffsize;

      nr=NULL;
      cCount = NULL;
      
      //cNR(loc,&nr);

      //Open a Net enumeration operation handle: hEnum.
    res = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, nr, hEnum);
   
      WNetGetLastError(&res,tempmsg,150,provider,150);

...

}
musakaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jhanceCommented:
Change:

LPHANDLE hEnum;

to:

HANDLE hEnum;


and also change:

res = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, nr, hEnum);


to:

res = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, nr, &hEnum);

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jhanceCommented:
Oops, one more thing.  I meant to say:

res = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, NULL, &hEnum);
0
musakaAuthor Commented:
Worked like a charm...

Thanks!
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

musakaAuthor Commented:
Worked like a charm...

Thanks!
0
jhanceCommented:
>Worked like a charm...

So why the "B" grade?
0
musakaAuthor Commented:
Two things...

1)  I generally reserve A's for when experts not only give solutions but also explain why the solution worked, otherwise I can't actually learn anything from the answer

2) Actually, although mpr.ll has stopped crashing, I'm not getting anything when I try to WNetEnumResource() on the handle that's returned.  If you wanna take a look I'll leave the code on the bottom.  It's returning with a res==0, and a cCount =1, but this should be the root of the network so I figure that cCount should be much higher and the one thing it's says it's returning is completely empty.  It has nothing in either remote or local provider name...it just says "Microsoft Network" under provider and comment.  I'm not sure what's going wrong...

int MSShare::Dir(NetEntity *loc, NetEntity *NEbuff, int buffsize) {

      HANDLE hEnum;
      
      LPNETRESOURCE nr;
      
      NETRESOURCE *NRbuff;
      
      unsigned long int counter,Tmp_Buffsize,res;
      
      DWORD cbBuff,cCount;
      
      Tmp_Buffsize=buffsize;
      

      nr=NULL;
      cCount = 0xFFFFFFFF;
      
      //cNR(loc,&nr);

      //Open a Net enumeration operation handle: hEnum.
    res = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, nr, &hEnum);
            cbBuff=50000;
            NRbuff=(NETRESOURCE *)malloc(cbBuff);

            if (res == 0) {
            cbBuff = 500000;
        NRbuff = (NETRESOURCE *)GlobalAlloc(GPTR, cbBuff);
        //Call the enumeration function.
        res = WNetEnumResource(hEnum, &cCount,NRbuff, &cbBuff);
        if (res == 0) {
                  counter=0;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.