1。获得系统的时间
SYSTEMTIME st;
GetSystemTime(&st);
2。应用ftp上传的代码
bool ftp_upload_imp(const string&filepath,const char*server,const char*path
,unsigned short port,const char*user,const char*password){
bool rtn=false;
HINTERNET hInternet = InternetOpenA("crash-report", PRE_CONFIG_INTERNET_ACCESS, NULL, NULL, 0);
HINTERNET conn=0;
if(hInternet)conn=InternetConnectA(hInternet,server,port,user,password,INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE,1);
if(conn){
if(FtpSetCurrentDirectoryA(conn,path)){
char t[1024];
strcpy_s(t,sizeof(t),filepath.c_str());
const char*fn=PathFindFileNameA(t);
if(::FtpPutFileA(conn,t,fn, FTP_TRANSFER_TYPE_BINARY, 1))
rtn=true;
}
}
if(conn)::InternetCloseHandle(conn);
if(hInternet)::InternetCloseHandle(hInternet);
return rtn;
}
3.设置系统的locale
if (::GetThreadLocale() == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED))
::SetThreadLocale(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED));
else
::SetThreadLocale(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
4.获取windows版本
bool older_than_windows_ver6(void){
OSVERSIONINFO oi={sizeof(OSVERSIONINFO)};
GetVersionEx(&oi);
return oi.dwMajorVersion<6;//vista or windows 2008
}
5.获取进程利用内存情况
PROCESS_MEMORY_COUNTERS pmc;
ZeroMemory(&pmc, sizeof(pmc));
GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
MEMORYSTATUS stat;
GlobalMemoryStatus (&stat);
6.创建事件与线程
bool bSuc=false;
do
{
//创建线程退出事件
if(!(_event=CreateEvent(NULL,TRUE,FALSE, NULL))) break;
//创建主线程
unsigned long threadid = 0;
HANDLE _thread = reinterpret_cast<HANDLE>(_beginthreadex(NULL,0,ThreadExecutive,this,0,reinterpret_cast<UINT*>(&threadid)));
if(!_thread) break;
//关闭主线程句柄
CloseHandle(_thread);
bSuc=true;
} while(0);
return bSuc;
7.避免默认的复制构造与拷贝构造函数的生成。
class nat_sessions_helper{
nat_sessions_helper(const nat_sessions_helper&);
nat_sessions_helper&operator=(const nat_sessions_helper&);
public:
nat_sessions_helper(void);
~nat_sessions_helper(void);
};
posted on 2009-09-18 14:31
Mitnick 阅读(155)
评论(0) 编辑 收藏 引用