MFC读取网络共享文件,从根目录开始

ShareDir.h

#pragma once

class CShareDir
{
public:
	CShareDir(void);
	~CShareDir(void);
public:
	void GetShareDir(CString lpszAddr,CStringArray &folderNames);
};

ShareDir.cpp

#include "StdAfx.h"
#include "ShareDir.h"
#include 
#pragma comment (lib,"mpr")
#pragma comment (lib,"netapi32")

CShareDir::CShareDir(void)
{
}

CShareDir::~CShareDir(void)
{
}

void CShareDir::GetShareDir(CString lpszAddr,CStringArray &folderNames)
{
	PSHARE_INFO_502 pBufPtr,p;
	NET_API_STATUS res;
	TCHAR szText[MAX_PATH];
	_stprintf(szText,L"\\\\%s",lpszAddr);
	WCHAR *plszServer = (LPTSTR)szText;
	DWORD dwEnriesRead = 0;
	DWORD dwTotalEntries = 0;
	DWORD dwResume = 0;
	do 
	{
		res = NetShareEnum(lpszAddr.AllocSysString(),502,(LPBYTE*)&pBufPtr,-1,&dwEnriesRead,&dwTotalEntries,&dwResume);
		if(res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
		{
			p = pBufPtr;
			for (DWORD i=0;ishi502_netname);
				p++;
			}
			NetApiBufferFree(pBufPtr);
		}
		else
		{
			AfxMessageBox(L"未读取到共享文件夹");
		}
	} while (res == ERROR_MORE_DATA);
}


你可能感兴趣的:(MFC,C++,C++,MFC)