WSADATA wsd;
WSAStartup(MAKEWORD(2,2),&wsd);
m_grid.SetExtendedStyle(LVS_EX_FLATSB|LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_ONECLICKACTIVATE|LVS_EX_GRIDLINES);
m_grid.InsertColumn(0,L"计算机名",LVCFMT_LEFT,200,0);
m_grid.InsertColumn(1,L"IP地址",LVCFMT_LEFT,200,0);
DWORD Count=0xFFFFFFFF,Bufsize=4096,Res;
NETRESOURCE* nRes;
NETRESOURCE* nRes1;
NETRESOURCE* nRes2;
HANDLE lphEnum;
LPVOID Buf=new char[4096];
LPVOID Buf1=new char[4096];
LPVOID Buf2=new char[4096];
Res=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,RESOURCEUSAGE_CONTAINER,NULL,&lphEnum);
Res=WNetEnumResource(lphEnum,&Count,Buf,&Bufsize);
nRes=(NETRESOURCE*)Buf;
for(DWORD n=0;n<Count;nRes++)
{
DWORD Count1=0xFFFFFFFF;
Res=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,RESOURCEUSAGE_CONTAINER,nRes,&lphEnum);
Res=WNetEnumResource(lphEnum,&Count1,Buf1,&Bufsize);
nRes1=(NETRESOURCE*)Buf1;
for(DWORD i=0;i<Count1;i++)
{
DWORD Count2=0xFFFFFFFF;
Res=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,RESOURCEUSAGE_CONTAINER,nRes1,&lphEnum);
Res=WNetEnumResource(lphEnum,&Count2,Buf2,&Bufsize);
nRes2=(NETRESOURCE*)Buf2;
for(DWORD j=0;j<Count2;j++,nRes2++)
{
m_grid.InsertItem(j,0);
CString sName=nRes->lpRemoteName;
sName=sName.Right(sName.GetLength()-2);
m_grid.SetItemText(j,0,sName);
CString str=_T("");
struct hostent * pHost;
pHost=gethostbyname((char*)(LPCTSTR)sName);
if(pHost==NULL)
m_grid.SetItemText(j,1,L"无法获得IP地址");
else
{
for(int n=0;n<4;n++)
{
CString addr;
if(n>0)
str+=".";
addr.Format(L"%u",(unsigned int)((unsigned char*)pHost->h_addr_list[0])[n]);
str+=addr; }
m_grid.SetItemText(j,1,str);
}
}
}
}
delete Buf;
delete Buf1;
delete Buf2;
WNetCloseEnum(lphEnum);
Res=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,RESOURCEUSAGE_CONTAINER,nRes,&lphEnum);
调试就是这一句不对,但是我不知道怎么修改,在VS2008中提示
未处理的异常0xC0000005读取位置0xcdcdcdcd时发生访问冲突
WSAStartup(MAKEWORD(2,2),&wsd);
m_grid.SetExtendedStyle(LVS_EX_FLATSB|LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_ONECLICKACTIVATE|LVS_EX_GRIDLINES);
m_grid.InsertColumn(0,L"计算机名",LVCFMT_LEFT,200,0);
m_grid.InsertColumn(1,L"IP地址",LVCFMT_LEFT,200,0);
DWORD Count=0xFFFFFFFF,Bufsize=4096,Res;
NETRESOURCE* nRes;
NETRESOURCE* nRes1;
NETRESOURCE* nRes2;
HANDLE lphEnum;
LPVOID Buf=new char[4096];
LPVOID Buf1=new char[4096];
LPVOID Buf2=new char[4096];
Res=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,RESOURCEUSAGE_CONTAINER,NULL,&lphEnum);
Res=WNetEnumResource(lphEnum,&Count,Buf,&Bufsize);
nRes=(NETRESOURCE*)Buf;
for(DWORD n=0;n<Count;nRes++)
{
DWORD Count1=0xFFFFFFFF;
Res=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,RESOURCEUSAGE_CONTAINER,nRes,&lphEnum);
Res=WNetEnumResource(lphEnum,&Count1,Buf1,&Bufsize);
nRes1=(NETRESOURCE*)Buf1;
for(DWORD i=0;i<Count1;i++)
{
DWORD Count2=0xFFFFFFFF;
Res=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,RESOURCEUSAGE_CONTAINER,nRes1,&lphEnum);
Res=WNetEnumResource(lphEnum,&Count2,Buf2,&Bufsize);
nRes2=(NETRESOURCE*)Buf2;
for(DWORD j=0;j<Count2;j++,nRes2++)
{
m_grid.InsertItem(j,0);
CString sName=nRes->lpRemoteName;
sName=sName.Right(sName.GetLength()-2);
m_grid.SetItemText(j,0,sName);
CString str=_T("");
struct hostent * pHost;
pHost=gethostbyname((char*)(LPCTSTR)sName);
if(pHost==NULL)
m_grid.SetItemText(j,1,L"无法获得IP地址");
else
{
for(int n=0;n<4;n++)
{
CString addr;
if(n>0)
str+=".";
addr.Format(L"%u",(unsigned int)((unsigned char*)pHost->h_addr_list[0])[n]);
str+=addr; }
m_grid.SetItemText(j,1,str);
}
}
}
}
delete Buf;
delete Buf1;
delete Buf2;
WNetCloseEnum(lphEnum);
Res=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,RESOURCEUSAGE_CONTAINER,nRes,&lphEnum);
调试就是这一句不对,但是我不知道怎么修改,在VS2008中提示
未处理的异常0xC0000005读取位置0xcdcdcdcd时发生访问冲突
解决方案 »
- accept 阻塞问题,在线等~
- 请问int如何转换成char[]
- 请问编写硬件相关的程序一般需要包含哪些头文件?
- 如何调用扫描仪获得图像?就像adobe photoshop软件里面"file"--"import"-"**scan..."那个功能一样
- 程序收到,请siphonelee(sifone) 前来领分
- 菜鸟问题:怎样做批处理文件
- 关于MSXML使用的问题
- 请教一个有关MSAA的问题,紧急,谢谢!!
- CSerialPort问题
- ========怎样在按下鼠标左键时改变光标?==============
- GetPrivateProfileString直接读取内容到CString?
- MFC中数字排序问题
LPVOID Buf1=new char[4096];
LPVOID Buf2=new char[4096];把你的几个数组初始化一下
lpNetResource
Pointer to a NETRESOURCE structure that specifies the container to enumerate. If the dwScope parameter is not RESOURCE_GLOBALNET, this parameter must be NULL. If this parameter is NULL, the root of the network is assumed. (The system organizes a network as a hierarchy; the root is the topmost container in the network.)If this parameter is not NULL, it must point to a NETRESOURCE structure. This structure can be filled in by the application or it can be returned by a call to the WNetEnumResource function. The NETRESOURCE structure must specify a container resource; that is, the RESOURCEUSAGE_CONTAINER value must be specified in the dwUsage parameter.To enumerate all network resources, an application can begin the enumeration by calling WNetOpenEnum with the lpNetResource parameter set to NULL, and then use the returned handle to call WNetEnumResource to enumerate resources. If one of the resources in the NETRESOURCE array returned by the WNetEnumResource function is a container resource, you can call WNetOpenEnum to open the resource for further enumeration.