Retrieving Information About a Network Resource的例子编译不过
如下:
#include "wtypes.h"
#include "winnt.h"
#include "windef.h"
#include "Winnetwk.h"
//
// Verify a server on the network. 
//
DWORD
CheckServer(
    LPTSTR pszServer
    )
{  
    DWORD          dwError;
    NETRESOURCE    nr;
    NETRESOURCE    nrOut;
    LPTSTR         pszSystem = NULL;          // pointer to variable-length strings
    LPVOID         lpBuffer  = &nrOut;        // buffer
    DWORD          cbResult  = sizeof(nrOut); // buffer size    //
    // Fill a block of memory with zeroes; then 
    //  initialize the NETRESOURCE structure. 
    //
    ZeroMemory(&nr, sizeof(nr));    nr.dwScope       = RESOURCE_GLOBALNET;
    nr.dwType        = RESOURCETYPE_ANY;
    nr.lpRemoteName  = pszServer;    //
    // First call the WNetGetResourceInformation function with 
    //  memory allocated to hold only a NETRESOURCE structure. This 
    //  method can succeed if all the NETRESOURCE pointers are NULL.
    //
    dwError = WNetGetResourceInformation(&nr, lpBuffer, &cbResult, &pszSystem);    //
    // If the call fails because the buffer is too small, 
    //   call the LocalAlloc function to allocate a larger buffer.
    //
    if (dwError == ERROR_MORE_DATA)
    {
        lpBuffer = LocalAlloc(LMEM_FIXED, cbResult);        if (lpBuffer == NULL)
        {
            dwError = ERROR_NOT_ENOUGH_MEMORY;
        }
        //
        // Call WNetGetResourceInformation again
        //  with the larger buffer.
        //
        else
        {
            dwError = WNetGetResourceInformation(&nr, lpBuffer, &cbResult, &pszSystem);
        }
    }
    if (dwError == NO_ERROR)
    {
        // If the call succeeds, process the contents of the 
        //  returned NETRESOURCE structure and the variable-length
        //  strings in lpBuffer. Then free the memory.
        //
        if (lpBuffer != &nrOut)
        {
            LocalFree(lpBuffer);
        }
    }    return dwError;
}
int main()
{
char str[]="\\\\172.16.80.212";
CheckServer(str)
return 0;
}错误是:
G:\netcon1\main.cpp(35) : error C2065: 'WNetGetResourceInformation' : undeclared identifier另外谁知道,怎么通过程序确定网络路径已经登陆过,一般以”\\192.168.0.10\d\x.bmp“访问文件 如果以前没有输入 用户名 密码 的话,将访问不到文件,如果从网上邻居登陆过一次就可以了,如果没登陆我也可以用WNetAddConnection2登陆,但是我不知道怎样确定是否登陆过????

解决方案 »

  1.   

    Windows NT/2000: Requires Windows NT 4.0 or later.
      Windows 95/98: Requires Windows 95 or later.
      Header: Declared in Winnetwk.h.
      Library: Use Mpr.lib.
      Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.
    这些都加了吗?
      

  2.   

    在工程里面添加库Mpr.lib.
      

  3.   

    在VC安裝目錄下查找'WNetGetResourceInformation",看在哪兒聲明了
      

  4.   

    include
    和lib 都加了
    编译都通不过
      

  5.   

    声明在winnetwk.h 515行,我都看到了,但编译器不认。
      

  6.   

    我的系统是 win2000 ad server ,vc 6.0 sp5
      

  7.   

    大家试一下 msdn 下只有一个函数,我简单的写了一个console project,我得msdn 是 july 2000
      

  8.   

    另外谁知道,怎么通过程序确定网络路径已经登陆过,一般以”\\192.168.0.10\d\x.bmp“访问文件 如果以前没有输入 用户名 密码 的话,将访问不到文件,如果从网上邻居登陆过一次就可以了,如果没登陆我也可以用WNetAddConnection2登陆,但是我不知道怎样确定是否登陆过????你就用WNetAddConnection2(...,NULL,NULL...)登陆,如果以前登陆过就不会出来登陆框。
      

  9.   

    WNetAddConnection2(&nr, NULL, NULL, CONNECT_INTERACTIVE /*|CONNECT_PROMPT*/ );