NetRemoteTOD调用失败

cnyu 2007-12-17 11:51:47
代码如下:
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).
的错误,请问这是什么原因?
...全文
129 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnyu 2007-12-17
  • 打赏
  • 举报
回复
这个例子我看了,但是我这个用法为什么会出错,而且总是调用失败?
yxz_lp 2007-12-17
  • 打赏
  • 举报
回复
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;
}

cnyu 2007-12-17
  • 打赏
  • 举报
回复
楼上的方法虽然编译能通过,可是仍然调用失败,并且会出现
First-chance exception in PowerOff.exe (KERNEL32.DLL): 0x000006BA: (no name).
的错误
yxz_lp 2007-12-17
  • 打赏
  • 举报
回复
NET_API_STATUS nStatus = NetRemoteTOD( L"\\\\time.nist.gov",(LPBYTE*)&lpTodInfo);

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧