在msdn中,NetShareEnum是这样描述的:NetShareEnum retrieves information about each shared resource on a server. The NetShareEnum function is obsolete. It is provided only for compatibility with LAN Manager and 16-bit versions of Windows. Win32-based applications should use the WNetEnumResource function.即获得在服务器上的每个共享资源,在16位机器上使用,已经过时了,win32位应用程序应该使用WNetEnumResource 函数。
而WNetEnumResource的描述是:The WNetEnumResource function continues a network-resource enumeration started by the WNetOpenEnum function. 
即枚举网络资源。
问题:1、网络资源包括局域网共享目录下的文件吗?
      2、WNetEnumResource 能否代替NetShareEnum 列出局域网中所有共享目录下的文件?
      3、在使用中,它们如何配合?

解决方案 »

  1.   

    1、列出的是网上邻居里面的东西,自然可以获得他们里面共享的文件
    2、当然
    3、配合什么?WNetEnumResource和NetShareEnum??
      

  2.   


    BOOL   WINAPI   EnumerateFunc(HWND   hwnd,     
                                                          HDC   hdc,     
                                                          LPNETRESOURCE   lpnr)   
      {     
          DWORD   dwResult,   dwResultEnum;   
          HANDLE   hEnum;   
          DWORD   cbBuffer   =   16384;             //   16K   is   a   good   size   
          DWORD   cEntries   =   -1;                   //   enumerate   all   possible   entries   
          LPNETRESOURCE   lpnrLocal;           //   pointer   to   enumerated   structures   
          DWORD   i;   
          //   
          //   Call   the   WNetOpenEnum   function   to   begin   the   enumeration.   
          //   
          dwResult   =   WNetOpenEnum(RESOURCE_GLOBALNET,   //   all   network   resources   
                                                          RESOURCETYPE_ANY,       //   all   resources   
                                                          0,                 //   enumerate   all   resources   
                                                          lpnr,           //   NULL   first   time   the   function   is   called   
                                                          &hEnum);     //   handle   to   the   resource   
        
          if   (dwResult   !=   NO_ERROR)   
          {       
              //   
              //   Process   errors   with   an   application-defined   error   handler.   
              //   
              NetErrorHandler(hwnd,   dwResult,   (LPSTR)"WNetOpenEnum");   
              return   FALSE;   
          }   
          //   
          //   Call   the   GlobalAlloc   function   to   allocate   resources.   
          //   
          lpnrLocal   =   (LPNETRESOURCE)   GlobalAlloc(GPTR,   cbBuffer);   
            
          do   
          {       
              //   
              //   Initialize   the   buffer.   
              //   
              ZeroMemory(lpnrLocal,   cbBuffer);   
              //   
              //   Call   the   WNetEnumResource   function   to   continue   
              //     the   enumeration.   
              //   
              dwResultEnum   =   WNetEnumResource(hEnum,             //   resource   handle   
                                                                              &cEntries,     //   defined   locally   as   -1   
                                                                              lpnrLocal,     //   LPNETRESOURCE   
                                                                              &cbBuffer);   //   buffer   size   
              //   
              //   If   the   call   succeeds,   loop   through   the   structures.   
              //   
              if   (dwResultEnum   ==   NO_ERROR)   
              {   
                  for(i   =   0;   i   <   cEntries;   i++)   
                  {   
                      //   Call   an   application-defined   function   to   
                      //     display   the   contents   of   the   NETRESOURCE   structures.   
                      //   
                      DisplayStruct(hdc,   &lpnrLocal[i]);   
        
                      //   If   the   NETRESOURCE   structure   represents   a   container   resource,     
                      //     call   the   EnumerateFunc   function   recursively.   
        
                      if(RESOURCEUSAGE_CONTAINER   ==   (lpnrLocal[i].dwUsage   
                                                                                    &   RESOURCEUSAGE_CONTAINER))   
                          if(!EnumerateFunc(hwnd,   hdc,   &lpnrLocal[i]))   
                              TextOut(hdc,   10,   10,   "EnumerateFunc   returned   FALSE.",   29);   
                  }   
              }   
              //   Process   errors.   
              //   
              else   if   (dwResultEnum   !=   ERROR_NO_MORE_ITEMS)   
              {   
                  NetErrorHandler(hwnd,   dwResultEnum,   (LPSTR)"WNetEnumResource");   
                  break;   
              }   
          }   
          //   
          //   End   do.   
          //   
          while(dwResultEnum   !=   ERROR_NO_MORE_ITEMS);   
          //   
          //   Call   the   GlobalFree   function   to   free   the   memory.   
          //   
          GlobalFree((HGLOBAL)lpnrLocal);   
          //   
          //   Call   WNetCloseEnum   to   end   the   enumeration.   
          //   
          dwResult   =   WNetCloseEnum(hEnum);   
            
          if(dwResult   !=   NO_ERROR)   
          {     
              //   
              //   Process   errors.   
              //   
              NetErrorHandler(hwnd,   dwResult,   (LPSTR)"WNetCloseEnum");   
              return   FALSE;   
          }   
        
          return   TRUE;   
      }   这段代码将会通过递归调用实现遍历文件并显示到一个DC中,MSDN的例子
      

  3.   

    谢谢,搞定了
    DisplayStruct是用户自定义打印信息的,可以是printf();
    NetErrorHandler   用户自定义打印错误信息的。不用管 屏蔽掉。
    调用时 EnumerateFunc(NULL,NULL,NULL);                      
      

  4.   

    WNetEnumResource是win32的api函数吗?
      

  5.   

    R3下用的32位的API都是Win32 API
      

  6.   

    枚举共享目录的函数能否移植到linux下?
      

  7.   

    有没有c/c++的网络开源类库,包含http/ftp/cifs(smb)/协议的?
      

  8.   

    你看看有没有谁去专门花大力气封装socket就好了
      

  9.   

    http://www.oschina.net/p/cpp+sockets这里有一个C++的网络包