代码如下:
int nHour;
LPTIME_OF_DAY_INFO lpTodInfo = NULL;
CString strHost = "\\\\time.windows.com";
NET_API_STATUS nStatus = NetRemoteTOD(strHost.AllocSysString(), (LPBYTE*)&lpTodInfo);
if ( nStatus == NERR_Success && lpTodInfo)
{
nHour = lpTodInfo->tod_hours;
TRACE("GetTimeOK.");
}
else
{
strHost = "\\\\time.nist.gov";
nStatus = NetRemoteTOD(strHost.AllocSysString(), (LPBYTE*)&lpTodInfo);
if ( nStatus == NERR_Success && lpTodInfo)
{
TRACE("GetTimeOK.");
}
}我用这段代码从网络服务器上获取时间,可是调用总是失败,而且会出现
First-chance exception in PowerOff.exe (KERNEL32.DLL): 0x000006BA: (no name).
的错误,请问这是什么原因?

解决方案 »

  1.   

    NET_API_STATUS   nStatus   =   NetRemoteTOD( L"\\\\time.nist.gov",(LPBYTE*)&lpTodInfo); 
      

  2.   

    楼上的方法虽然编译能通过,可是仍然调用失败,并且会出现
    First-chance exception in PowerOff.exe (KERNEL32.DLL): 0x000006BA: (no name).
    的错误
      

  3.   

    msdn上的例子#ifndef UNICODE
    #define UNICODE
    #endif#include <stdio.h>
    #include <windows.h> 
    #include <lm.h>int wmain(int argc, wchar_t *argv[])
    {
       LPTIME_OF_DAY_INFO pBuf = NULL;
       NET_API_STATUS nStatus;
       LPTSTR pszServerName = NULL;   if (argc > 2)
       {
          fwprintf(stderr, L"Usage: %s [\\\\ServerName]\n", argv[0]);
          exit(1);
       }
       // The server is not the default local computer.
       //
       if (argc == 2)
          pszServerName = argv[1];
       //
       // Call the NetRemoteTOD function.
       //
       nStatus = NetRemoteTOD(pszServerName,
                              (LPBYTE *)&pBuf);
       //
       // If the function succeeds, display the current date and time.
       //
       if (nStatus == NERR_Success)
       {
          if (pBuf != NULL)
          {
             fprintf(stderr, "\nThe current date is: %d/%d/%d\n",
                     pBuf->tod_month, pBuf->tod_day, pBuf->tod_year);
             fprintf(stderr, "The current time is: %d:%d:%d\n",
                     pBuf->tod_hours, pBuf->tod_mins, pBuf->tod_secs);
          }
       }
       //
       // Otherwise, display a system error.
       else
          fprintf(stderr, "A system error has occurred: %d\n", nStatus);
       //
       // Free the allocated buffer.
       //
       if (pBuf != NULL)
          NetApiBufferFree(pBuf);   return 0;
    }