Common.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:1k
源码类别:
P2P编程
开发平台:
Visual C++
- // Common.cpp: implementation of the CCommon class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "testbt.h"
- #include "Common.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- string ltostring(long lVal)
- {
- char str[100] = {0};
- sprintf(str, "%d", (unsigned long) lVal);
- return string(str);
- }
- string WSAShowError()
- {
- TCHAR errMsg[2048] = {0};
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
- GetModuleHandle(TEXT("ws2_32.dll")), WSAGetLastError(),
- NULL,
- errMsg,
- sizeof(errMsg)/sizeof(TCHAR),
- NULL);
- // MessageBox(ghMainWnd, errMsg, TEXT("ws2_32.dll"), MB_ICONERROR);
- return string(errMsg);
- }
- bool IsEventSet(HANDLE hEvent)
- {
- return WaitForSingleObject(hEvent, 0) == WAIT_OBJECT_0;
- }