SDK一个很费解的问题,请求帮助!!!
程序代码:
void socketnet(HWND hwnd) { WSADATA wsaData; //初始化Socket库 WSAStartup(MAKEWORD(2,0),&wsaData); //创建一根电线 SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); SOCKADDR_IN sa; sa.sin_family=AF_INET; //设置电线连接服务器端的端口 sa.sin_port = htons(IPPORT_TIMESERVER); //123.125.50.135是ping smtp.出来的,后面会讲使用gethostbyname来直接从 //主机名得到ip地址 sa.sin_addr.S_un.S_addr = inet_addr("210.0.235.14");//与time.同步 //为什么不用设置客户端的端口,难道不需要客户端的端口吗? if(connect(sock,(SOCKADDR *)&sa,sizeof(sa))==SOCKET_ERROR) { ShowError(); return; } unsigned long ulTime; recv(sock,(char *)&ulTime,sizeof(unsigned long),0); ulTime = ntohl(ulTime); SYSTEMTIME st; UINT64 uiCurTime, uiBaseTime, uiResult; uiBaseTime = ((UINT64) HIGHTIME << 32) + LOWTIME; uiCurTime = (UINT64)ulTime * (UINT64)10000000; uiResult = uiBaseTime + uiCurTime; FileTimeToSystemTime((LPFILETIME)&uiResult, &st); TCHAR Buffer[256]; ZeroMemory(buffer,sizeof(buffer)/sizeof(char)); wsprintf(Buffer,TEXT("%s年%s月%s日 %s时%s分%s秒"),st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond); SetDlgItemText(hwnd,IDC_EDIT1,Buffer); SetSystemTime(&st);//设置系统时间 closesocket(sock); WSACleanup(); }检查调试发现运行到这句就出现内存错误!
很是费解,请求高手帮忙!!!!
wsprintf(Buffer,TEXT("%s年%s月%s日 %s时%s分%s秒"),st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond);