HANDLE hWNetEnum;
DWORD DResult;
NETRESOURCE nr;
CHAR SysName[512];
char RemoteUserName[512];
DWORD UseCount=1;
DWORD charCount=512;
DWORD dwBuffer = 16384 ; // 16K is reasonable size
DWORD dwEntries = 0xFFFFFFFF ; // enumerate all possible entries
LPNETRESOURCE lpnrLocal = 0;
CString LocalServerName,strPws;
LPNETINFOSTRUCT InfoNet;
nr.dwScope = RESOURCE_GLOBALNET;
nr.dwType = RESOURCETYPE_ANY;
nr.dwDisplayType = RESOURCEDISPLAYTYPE_SERVER;
nr.dwUsage = RESOURCEUSAGE_CONTAINER;
nr.lpLocalName = NULL;
nr.lpRemoteName =NULL; //g_Inet.m_url;
nr.lpComment = NULL;
nr.lpProvider = NULL;
LocalServerName="H:";
strPws="seedchina";
DWORD dwType=RESOURCETYPE_ANY;
DResult=WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, &nr, &hWNetEnum);
switch(DResult)
{
case NO_ERROR:
// ::AfxMessageBox("成功");
break;
case ERROR_NOT_CONTAINER:
::AfxMessageBox("没有网络容器");
break;
case ERROR_NO_NETWORK:
::AfxMessageBox("没有发现网络!");
break;
case ERROR_EXTENDED_ERROR:
::AfxMessageBox("网络错误!");
break;
}
do {
lpnrLocal = (LPNETRESOURCE) GlobalAlloc( GPTR, dwBuffer ) ;
DResult=WNetEnumResource(hWNetEnum,&dwEntries,lpnrLocal,&dwBuffer);
if(DResult==NO_ERROR)
{
// UserName.Format("%s\n", SysName);
for( register DWORD i = 0 ; i < dwEntries ; i++ )
{
::AfxMessageBox(lpnrLocal[i].lpRemoteName);
::AfxMessageBox(lpnrLocal[i].lpLocalName);
}
// ::AfxMessageBox((LPCTSTR)SysName);
}
// CDialog::OnOK();
} while (DResult == NO_ERROR);
DWORD DResult;
NETRESOURCE nr;
CHAR SysName[512];
char RemoteUserName[512];
DWORD UseCount=1;
DWORD charCount=512;
DWORD dwBuffer = 16384 ; // 16K is reasonable size
DWORD dwEntries = 0xFFFFFFFF ; // enumerate all possible entries
LPNETRESOURCE lpnrLocal = 0;
CString LocalServerName,strPws;
LPNETINFOSTRUCT InfoNet;
nr.dwScope = RESOURCE_GLOBALNET;
nr.dwType = RESOURCETYPE_ANY;
nr.dwDisplayType = RESOURCEDISPLAYTYPE_SERVER;
nr.dwUsage = RESOURCEUSAGE_CONTAINER;
nr.lpLocalName = NULL;
nr.lpRemoteName =NULL; //g_Inet.m_url;
nr.lpComment = NULL;
nr.lpProvider = NULL;
LocalServerName="H:";
strPws="seedchina";
DWORD dwType=RESOURCETYPE_ANY;
DResult=WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, &nr, &hWNetEnum);
switch(DResult)
{
case NO_ERROR:
// ::AfxMessageBox("成功");
break;
case ERROR_NOT_CONTAINER:
::AfxMessageBox("没有网络容器");
break;
case ERROR_NO_NETWORK:
::AfxMessageBox("没有发现网络!");
break;
case ERROR_EXTENDED_ERROR:
::AfxMessageBox("网络错误!");
break;
}
do {
lpnrLocal = (LPNETRESOURCE) GlobalAlloc( GPTR, dwBuffer ) ;
DResult=WNetEnumResource(hWNetEnum,&dwEntries,lpnrLocal,&dwBuffer);
if(DResult==NO_ERROR)
{
// UserName.Format("%s\n", SysName);
for( register DWORD i = 0 ; i < dwEntries ; i++ )
{
::AfxMessageBox(lpnrLocal[i].lpRemoteName);
::AfxMessageBox(lpnrLocal[i].lpLocalName);
}
// ::AfxMessageBox((LPCTSTR)SysName);
}
// CDialog::OnOK();
} while (DResult == NO_ERROR);
LPWSTR *lpGroupNameBuffer;
PNETSETUP_JOIN_STATUS pBufferType;
NET_API_STATUS status=NetGetJoinInformation( L"computerName",lpGroupNameBuffer,pBufferType);
DWORD dwError=GetLastError();
CString strGroupName(*lpGroupNameBuffer);
得到status为998,Invalid access to memory location.
dwError为997,Overlapped I/O operation is in progress。
如果将computerName改为NULL,则运行到NetGetJointInformation会出错:弹出对话框:unhandled exception in my.exe(netapi32.dll),0XC0000005:Access Violation.
LPWSTR *lpGroupNameBuffer;
PNETSETUP_JOIN_STATUS pBufferType;
NET_API_STATUS status=NetGetJoinInformation( L"computerName",lpGroupNameBuffer,pBufferType);
DWORD dwError=GetLastError();
CString strGroupName(*lpGroupNameBuffer);
得到status为998,Invalid access to memory location.
dwError为997,Overlapped I/O operation is in progress。
如果将computerName改为NULL,则运行到NetGetJointInformation会出错:弹出对话框:unhandled exception in my.exe(netapi32.dll),0XC0000005:Access Violation
NETSETUP_JOIN_STATUS pBufferType;
NET_API_STATUS status=NetGetJoinInformation( L"computerName",lpGroupNameBuffer,&BufferType);
还是不行,会弹出unhandled exception in my.exe(netapi32.dll),0XC0000005:Access Violation错误,
是不是我的netapi32.dll,版本太低,
我刚下载SDK中中有Lmjoin.h和Netapi32.lib,
但是没发现netapi32.dll.
NETSETUP_JOIN_STATUS BufferType;
NET_API_STATUS status=NetGetJoinInformation( L"computerName",&lpGroupNameBuffer,&BufferType);
就是有点疑惑,还请yu_hl(卖柴火的小男孩)给解释一下:
LPWSTR *lpGroupNameBuffer;
LPWSTR lpGroupNameBuffer;
调用成功与否的原因。