Link to home
Start Free TrialLog in
Avatar of musaka
musaka

asked on

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);

...

}
ASKER CERTIFIED SOLUTION
Avatar of jhance
jhance

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jhance
jhance

Oops, one more thing.  I meant to say:

res = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, NULL, &hEnum);
Avatar of musaka

ASKER

Worked like a charm...

Thanks!
Avatar of musaka

ASKER

Worked like a charm...

Thanks!
>Worked like a charm...

So why the "B" grade?
Avatar of musaka

ASKER

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;