[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 401
  • Last Modified:

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

...

}
0
musaka
Asked:
musaka
  • 3
  • 3
1 Solution
 
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now