void CHawkeye_clientApp::SendData(DWORD Delay,TCHAR* procName) { Mesinfo mi; CString addr; UINT port; clasock->GetSockName(addr,port); lstrcpy(mi.mip,addr.GetBuffer(addr.GetLength())); addr.ReleaseBuffer(); mi.mport = port; mi.mdelay = Delay; lstrcpy(mi.mprocname,procName); clasock->Send(&mi,sizeof(mi)); CString dtime; _wstrtime((TCHAR*)dtime.GetString()); phe->m_listlog.InsertItem(0,dtime); phe->m_listlog.SetItemText(0,1,L"SEND"); //TCHAR temp[128]; //wsprintf(temp,L"[%d ms] [%s]",Delay,procName.GetString()); phe->m_listlog.SetItemText(0,2,mi.mprocname); phe->m_listlog.UpdateData(false); }
void CHawkeye_clientApp::DisConnectServ() { CString dtime; _wstrtime((TCHAR*)dtime.GetString()); phe->m_listlog.InsertItem(0,dtime); phe->m_listlog.SetItemText(0,1,L"NETWORK"); phe->m_listlog.SetItemText(0,2,L"Disconnected"); phe->m_listlog.UpdateData(false); isConnect = false; }
static void test_wstrtime(void) { wchar_t time[16], * result; int hour, minute, second, count, len; wchar_t format[] = { '%','0','2','d',':','%','0','2','d',':','%','0','2','d',0 }; result = _wstrtime(time); ok(result == time, "Wrong return value\n"); len = wcslen(time); ok(len == 8, "Wrong length: returned %d, should be 8\n", len); count = swscanf(time, format, &hour, &minute, &second); ok(count == 3, "Wrong format: count = %d, should be 3\n", count); }
BOOL CHawkeye_clientApp::ConnectServ() { CHKSock* pSock = new CHKSock(); pSock->Create(); isConnect = TRUE; CString dtime; _wstrtime((TCHAR*)dtime.GetString()); phe->m_listlog.InsertItem(0,dtime); phe->m_listlog.SetItemText(0,1,L"NETWORK"); phe->m_listlog.SetItemText(0,2,L"Connected"); phe->m_listlog.UpdateData(false); clasock = pSock; return TRUE; }
/********************************************************************* * _wstrtime_s (MSVCRT.@) */ int CDECL _wstrtime_s(MSVCRT_wchar_t* time, MSVCRT_size_t size) { if(time && size) time[0] = '\0'; if(!time) { *MSVCRT__errno() = MSVCRT_EINVAL; return MSVCRT_EINVAL; } if(size < 9) { *MSVCRT__errno() = MSVCRT_ERANGE; return MSVCRT_ERANGE; } _wstrtime(time); return 0; }
int __stdcall WriteConsoleLog( const TCHAR *msg, const int error, const TCHAR *location ) { std::wstreambuf *buf; TCHAR time[9]; LPTSTR err_buf; buf = std::wcout.rdbuf( ); std::wcout.imbue( std::locale( ".866" ) ); _wstrtime( time ); std::wcout << time << tab; if( error == 0 ) { std::wcout << msg; } else { if( !FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_MAX_WIDTH_MASK, 0, error, MAKELANGID( LANG_NEUTRAL, SUBLANG_SYS_DEFAULT ), (LPTSTR) &err_buf, 0, 0 ) ) return GetLastError( ); std::wcout << L"Error: " << msg << tab << L"(" << error << L") " << err_buf << tab << location; LocalFree( err_buf ); } if( std::wcout.fail( ) ) { std::wcout.rdbuf( buf ); } std::wcout << std::endl; return 0; }
int __stdcall WriteLog( const TCHAR *msg, const int error, const TCHAR *location ) { static TCHAR log_path[MAX_PATH] = { }; static bool first_call = FirstCall( log_file ); std::wofstream log; TCHAR date[9]; TCHAR time[9]; LPTSTR err_buf; if( !*log_path ) { if( !GetModuleFileName( 0, log_path, MAX_PATH ) ) return -1; wcscpy( wcsrchr( log_path, L'.' ) + 1, L"log" ); } log.open( log_path, std::ios::app ); if( log.fail( ) ) return -1; log.imbue( std::locale( "rus_rus" ) ); if( first_call ) { first_call = false; _wstrdate( date ); if( log.rdbuf( )->pubseekoff( 0, std::ios_base::end ) > 0 ) log << std :: endl; log << date << tab << L"log started" << std::endl; } _wstrtime( time ); log << time << tab; if( error == 0 ) { log << msg; } else { if( !FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_MAX_WIDTH_MASK, 0, error, MAKELANGID( LANG_NEUTRAL, SUBLANG_SYS_DEFAULT ), (LPTSTR) &err_buf, 0, 0 ) ) return GetLastError( ); log << L"Error: " << msg << tab << L"(" << error << L") " << err_buf << tab << location; LocalFree( err_buf ); } if( log.fail( ) ) { log.close( ); log.open( log_path, std::ios::app ); } log << std::endl; log.close( ); return 0; }
static char_t* strtime(char_t* p) { return _wstrtime(p); }
void CHawkeye_clientApp::ReceiveData() { CommandMes cm; clasock->Receive(&cm,sizeof(cm)); if(cm.mtype == SELF_KILLING) { SelfKilling(); } else if(cm.mtype == REG_TRUE) { phe->m_againreg = true; phe->SetRegistyStartProgram(TRUE); CString dtime; _wstrtime((TCHAR*)dtime.GetString()); phe->m_listlog.InsertItem(0,dtime); phe->m_listlog.SetItemText(0,1,L"COMMAND"); phe->m_listlog.SetItemText(0,2,L"Regstry Able"); phe->m_listlog.UpdateData(false); } else if(cm.mtype == REG_FALSE) { phe->m_againreg = false; phe->SetRegistyStartProgram(FALSE); CString dtime; _wstrtime((TCHAR*)dtime.GetString()); phe->m_listlog.InsertItem(0,dtime); phe->m_listlog.SetItemText(0,1,L"COMMAND"); phe->m_listlog.SetItemText(0,2,L"Regstry Disable"); phe->m_listlog.UpdateData(false); } else if(cm.mtype == SEND_MES) { AfxMessageBox(cm.minfo,MB_ICONEXCLAMATION); CString dtime; _wstrtime((TCHAR*)dtime.GetString()); phe->m_listlog.InsertItem(0,dtime); phe->m_listlog.SetItemText(0,1,L"COMMAND"); phe->m_listlog.SetItemText(0,2,L"Message"); phe->m_listlog.UpdateData(false); } else if(cm.mtype == ON_PROGRAM) { ::ShellExecute(NULL, L"open", cm.minfo,L"", NULL, SW_SHOW); CString dtime; _wstrtime((TCHAR*)dtime.GetString()); phe->m_listlog.InsertItem(0,dtime); phe->m_listlog.SetItemText(0,1,L"COMMAND"); phe->m_listlog.SetItemText(0,2,L"Execute"); phe->m_listlog.UpdateData(false); } else if(cm.mtype == TM_PROGRAM) { HWND hExit; hExit = ::FindWindowW(NULL,cm.minfo); if(hExit != NULL) { ::PostMessageW(hExit,WM_QUIT,0,0); CString dtime; _wstrtime((TCHAR*)dtime.GetString()); phe->m_listlog.InsertItem(0,dtime); phe->m_listlog.SetItemText(0,1,L"COMMAND"); phe->m_listlog.SetItemText(0,2,L"Terminate"); phe->m_listlog.UpdateData(false); } } else if(cm.mtype == SHUT_DOWN) { phe->SystemShutdown(0); CString dtime; _wstrtime((TCHAR*)dtime.GetString()); phe->m_listlog.InsertItem(0,dtime); phe->m_listlog.SetItemText(0,1,L"COMMAND"); phe->m_listlog.SetItemText(0,2,L"Shutdown"); phe->m_listlog.UpdateData(false); } else if(cm.mtype == RE_BOOT) { phe->SystemShutdown(1); CString dtime; _wstrtime((TCHAR*)dtime.GetString()); phe->m_listlog.InsertItem(0,dtime); phe->m_listlog.SetItemText(0,1,L"COMMAND"); phe->m_listlog.SetItemText(0,2,L"Reboot"); phe->m_listlog.UpdateData(false); } else if(cm.mtype == RE_BOOT) { phe->SystemShutdown(2); CString dtime; _wstrtime((TCHAR*)dtime.GetString()); phe->m_listlog.InsertItem(0,dtime); phe->m_listlog.SetItemText(0,1,L"COMMAND"); phe->m_listlog.SetItemText(0,2,L"Hibernates"); phe->m_listlog.UpdateData(false); } else if(cm.mtype == BLOCK_PROGRAM) { phe->InsertBlockList(cm.minfo); CString dtime; _wstrtime((TCHAR*)dtime.GetString()); phe->m_listlog.InsertItem(0,dtime); phe->m_listlog.SetItemText(0,1,L"COMMAND"); phe->m_listlog.SetItemText(0,2,L"InsertBlock"); phe->m_listlog.UpdateData(false); } else if(cm.mtype == UNBLOCK_PROGRAM) { phe->DeleteBlockList(cm.minfo); CString dtime; _wstrtime((TCHAR*)dtime.GetString()); phe->m_listlog.InsertItem(0,dtime); phe->m_listlog.SetItemText(0,1,L"COMMAND"); phe->m_listlog.SetItemText(0,2,L"DeleteBlock"); phe->m_listlog.UpdateData(false); } else if(cm.mtype == ALLRELEASE_PROGRAM) { phe->AllDeleteBlockList(); CString dtime; _wstrtime((TCHAR*)dtime.GetString()); phe->m_listlog.InsertItem(0,dtime); phe->m_listlog.SetItemText(0,1,L"COMMAND"); phe->m_listlog.SetItemText(0,2,L"AllRelease"); phe->m_listlog.UpdateData(false); } }