Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
jlib
Commits
19de8857
Commit
19de8857
authored
Aug 08, 2015
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
468f8cf6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
132 additions
and
110 deletions
+132
-110
Log.h
Log.h
+10
-7
MtVerify.h
MtVerify.h
+98
-103
initsock.h
initsock.h
+24
-0
No files found.
Log.h
View file @
19de8857
...
...
@@ -36,7 +36,8 @@
CLock
CLog
::
m_lockForSingleton
;
\
char
CLog
::
m_ansiBuf
[
MAX_OUTPUT_LEN
];
\
wchar_t
CLog
::
m_utf16Buf
[
MAX_OUTPUT_LEN
];
\
CLog
*
CLog
::
m_pInstance
=
NULL
;
CLog
*
CLog
::
m_pInstance
=
NULL
;
\
TCHAR
CLog
::
g_szFileName
[
1024
]
=
{
0
};
/*
#define TRACEFUNCNAME \
...
...
@@ -46,9 +47,9 @@
OutputDebugString(str);\
UNINIT_SYM();\
*/
#define MAX_OUTPUT_LEN
4096
#define MAX_FILE_LEN
1024 * 1024 * 10
static
TCHAR
g_szFileName
[
1024
]
=
{
0
};
#define MAX_OUTPUT_LEN
(1024 * 64)
#define MAX_FILE_LEN
(1024 * 1024 * 10)
//
static TCHAR g_szFileName[1024] = {0};
class
CLog
{
...
...
@@ -65,6 +66,7 @@ private:
BOOL
m_bRunning
;
FILE
*
m_pLogFile
;
PROCESS_INFORMATION
pi
;
static
TCHAR
g_szFileName
[
1024
];
static
CRITICAL_SECTION
m_cs
;
static
CLock
m_lockForSingleton
;
static
char
m_ansiBuf
[
MAX_OUTPUT_LEN
];
...
...
@@ -323,7 +325,8 @@ protected:
}
}
WORD
FormatBuf
(
const
TCHAR
*
oldBuf
,
TCHAR
*
newBuf
,
WORD
max_new_buff_len
=
MAX_OUTPUT_LEN
){
DWORD
FormatBuf
(
const
TCHAR
*
oldBuf
,
TCHAR
*
newBuf
,
DWORD
max_new_buff_len
=
MAX_OUTPUT_LEN
)
{
static
SYSTEMTIME
st
;
static
TCHAR
sztime
[
128
];
memset
(
sztime
,
0
,
sizeof
sztime
);
...
...
@@ -332,10 +335,10 @@ protected:
st
.
wYear
,
st
.
wMonth
,
st
.
wDay
,
(
st
.
wDayOfWeek
!=
0
)
?
st
.
wDayOfWeek
:
7
,
st
.
wHour
,
st
.
wMinute
,
st
.
wSecond
,
st
.
wMilliseconds
);
lstrcpy
(
newBuf
,
sztime
);
if
(
lstrlen
(
sztime
)
+
lstrlen
(
oldBuf
)
<
max_new_buff_len
){
if
(
static_cast
<
DWORD
>
(
lstrlen
(
sztime
)
+
lstrlen
(
oldBuf
)
)
<
max_new_buff_len
){
lstrcat
(
newBuf
,
oldBuf
);
}
return
static_cast
<
unsigned
short
>
(
lstrlen
(
newBuf
));
return
static_cast
<
DWORD
>
(
lstrlen
(
newBuf
));
}
void
OutputFile
(
const
TCHAR
*
buf
){
...
...
MtVerify.h
View file @
19de8857
...
...
@@ -35,7 +35,7 @@ __inline void PrintError(LPCTSTR linedesc, LPCTSTR filename, int lineno, DWORD e
NULL
);
_stprintf
(
errbuf
,
_T
(
"
\n
The following call failed at line %d in %s:
\n\n
%s
\n\n
Reason: %s
\n
"
),
lineno
,
filename
,
linedesc
,
lpBuffer
);
lineno
,
filename
,
linedesc
,
lpBuffer
);
#ifndef _WINDOWS_
WriteFile
(
GetStdHandle
(
STD_ERROR_HANDLE
),
errbuf
,
lstrlen
(
errbuf
),
&
numread
,
FALSE
);
...
...
@@ -55,14 +55,12 @@ __inline void PrintError(LPCTSTR linedesc, LPCTSTR filename, int lineno, DWORD e
__inline
void
WaitTillThreadActive
(
HANDLE
&
handle
)
{
if
(
handle
!=
INVALID_HANDLE_VALUE
)
{
if
(
handle
!=
INVALID_HANDLE_VALUE
)
{
BOOL
rc
=
FALSE
;
DWORD
ec
=
0
;
for
(;;)
{
for
(;;)
{
rc
=
GetExitCodeThread
(
handle
,
&
ec
);
if
(
rc
&&
(
ec
==
STILL_ACTIVE
))
if
(
rc
&&
(
ec
==
STILL_ACTIVE
))
break
;
Sleep
(
500
);
}
...
...
@@ -72,42 +70,41 @@ __inline void WaitTillThreadActive(HANDLE &handle)
/*
__inline void WaitTillThreadExited(HANDLE &handle, DWORD dwMilliseconds = 3000)
{
if(handle != INVALID_HANDLE_VALUE)
{
BOOL rc = FALSE;
DWORD ec = 0;
DWORD dwStart = GetTickCount();
for(;;)
{
if(GetTickCount() - dwStart >= dwMilliseconds)
{
::TerminateThread(handle, 0xffffffff);
CloseHandle(handle);
handle = INVALID_HANDLE_VALUE;
break;
}
if(handle == INVALID_HANDLE_VALUE)
break;
rc = GetExitCodeThread(handle, &ec);
if(rc && (ec != STILL_ACTIVE))
{
CloseHandle(handle);
handle = INVALID_HANDLE_VALUE;
break;
}
Sleep(500);
}
}
if(handle != INVALID_HANDLE_VALUE)
{
BOOL rc = FALSE;
DWORD ec = 0;
DWORD dwStart = GetTickCount();
for(;;)
{
if(GetTickCount() - dwStart >= dwMilliseconds)
{
::TerminateThread(handle, 0xffffffff);
CloseHandle(handle);
handle = INVALID_HANDLE_VALUE;
break;
}
if(handle == INVALID_HANDLE_VALUE)
break;
rc = GetExitCodeThread(handle, &ec);
if(rc && (ec != STILL_ACTIVE))
{
CloseHandle(handle);
handle = INVALID_HANDLE_VALUE;
break;
}
Sleep(500);
}
}
}
*/
__forceinline
void
WaitTillThreadExited
(
HANDLE
&
handle
,
DWORD
dwMilliseconds
=
5000
)
{
if
(
handle
==
INVALID_HANDLE_VALUE
)
if
(
handle
==
INVALID_HANDLE_VALUE
)
return
;
DWORD
ret
=
::
WaitForSingleObject
(
handle
,
dwMilliseconds
);
if
(
ret
!=
WAIT_OBJECT_0
)
{
//::TerminateThread(handle, 0xffffffff);
if
(
ret
!=
WAIT_OBJECT_0
)
{
//::TerminateThread(handle, 0xffffffff);
}
CloseHandle
(
handle
);
handle
=
INVALID_HANDLE_VALUE
;
...
...
@@ -115,17 +112,15 @@ __forceinline void WaitTillThreadExited(HANDLE &handle, DWORD dwMilliseconds = 5
__inline
LPTSTR
GetModuleFilePath
()
{
static
TCHAR
szPath
[
MAX_PATH
]
=
{
'\0'
};
if
(
lstrlen
(
szPath
)
!=
0
)
static
TCHAR
szPath
[
MAX_PATH
]
=
{
'\0'
};
if
(
lstrlen
(
szPath
)
!=
0
)
return
szPath
;
TCHAR
szExe
[
MAX_PATH
];
GetModuleFileName
(
GetModuleHandle
(
NULL
),
szExe
,
MAX_PATH
);
int
len
=
lstrlen
(
szExe
);
for
(
int
i
=
len
;
i
>
0
;
i
--
)
{
if
(
szExe
[
i
]
==
'\\'
)
{
for
(
int
i
=
len
;
i
>
0
;
i
--
)
{
if
(
szExe
[
i
]
==
'\\'
)
{
szExe
[
i
]
=
'\0'
;
lstrcpy
(
szPath
,
szExe
);
break
;
...
...
@@ -143,26 +138,26 @@ __inline LPTSTR GetModuleFilePath()
//安全删除对话框类堆内存
#define SAFEDELETEDLG(pDlg) {\
if
((
pDlg
))
{
\
if
(
::
IsWindow
(
pDlg
->
m_hWnd
))
{
\
(
pDlg
)
->
DestroyWindow
();
\
if
(
::
IsWindow
(
pDlg
->
m_hWnd
))
{
\
(
pDlg
)
->
DestroyWindow
();
\
}
\
delete
(
pDlg
);
\
(
pDlg
)
=
NULL
;
\
delete
(
pDlg
);
\
(
pDlg
)
=
NULL
;
\
}
\
}
//关闭核心对象句柄
#define CLOSEHANDLE(h){\
if
(
h
!=
INVALID_HANDLE_VALUE
&&
h
!=
NULL
)
{
\
::
CloseHandle
(
h
);
\
h
=
INVALID_HANDLE_VALUE
;
\
::
CloseHandle
(
h
);
\
h
=
INVALID_HANDLE_VALUE
;
\
}
\
}
#define CLOSESOCKET(s){\
if
(
s
!=
INVALID_SOCKET
){
\
if
(
s
!=
INVALID_SOCKET
)
{
\
::
closesocket
(
s
);
\
s
=
INVALID_SOCKET
;
\
s
=
INVALID_SOCKET
;
\
}
\
}
...
...
@@ -179,21 +174,21 @@ __forceinline LPSTR Utf16ToAnsi(const wchar_t * const wSrc)
{
char
*
pElementText
;
int
iTextLen
;
iTextLen
=
WideCharToMultiByte
(
CP_ACP
,
0
,
wSrc
,
-
1
,
NULL
,
0
,
NULL
,
NULL
);
iTextLen
=
WideCharToMultiByte
(
CP_ACP
,
0
,
wSrc
,
-
1
,
NULL
,
0
,
NULL
,
NULL
);
pElementText
=
new
char
[
iTextLen
+
1
];
memset
(
(
void
*
)
pElementText
,
0
,
sizeof
(
char
)
*
(
iTextLen
+
1
)
);
::
WideCharToMultiByte
(
CP_ACP
,
0
,
wSrc
,
-
1
,
pElementText
,
iTextLen
,
NULL
,
NULL
);
memset
(
(
void
*
)
pElementText
,
0
,
sizeof
(
char
)
*
(
iTextLen
+
1
)
);
::
WideCharToMultiByte
(
CP_ACP
,
0
,
wSrc
,
-
1
,
pElementText
,
iTextLen
,
NULL
,
NULL
);
return
pElementText
;
}
__forceinline
BOOL
Utf16ToAnsiUseCharArray
(
const
wchar_t
*
const
wSrc
,
char
*
ansiArr
,
WORD
ansiArrLen
)
__forceinline
BOOL
Utf16ToAnsiUseCharArray
(
const
wchar_t
*
const
wSrc
,
char
*
ansiArr
,
D
WORD
ansiArrLen
)
{
int
iTextLen
=
WideCharToMultiByte
(
CP_ACP
,
0
,
wSrc
,
-
1
,
NULL
,
0
,
NULL
,
NULL
);
if
(
iTextLen
<
ansiArrLen
)
{
memset
(
(
void
*
)
ansiArr
,
0
,
sizeof
(
char
)
*
(
iTextLen
+
1
)
);
::
WideCharToMultiByte
(
CP_ACP
,
0
,
wSrc
,
-
1
,
ansiArr
,
iTextLen
,
NULL
,
NULL
);
int
iTextLen
=
WideCharToMultiByte
(
CP_ACP
,
0
,
wSrc
,
-
1
,
NULL
,
0
,
NULL
,
NULL
);
if
(
static_cast
<
DWORD
>
(
iTextLen
)
<
ansiArrLen
)
{
memset
(
(
void
*
)
ansiArr
,
0
,
sizeof
(
char
)
*
(
iTextLen
+
1
)
);
::
WideCharToMultiByte
(
CP_ACP
,
0
,
wSrc
,
-
1
,
ansiArr
,
iTextLen
,
NULL
,
NULL
);
return
TRUE
;
}
return
FALSE
;
...
...
@@ -202,21 +197,21 @@ __forceinline BOOL Utf16ToAnsiUseCharArray(const wchar_t * const wSrc,
__forceinline
wchar_t
*
AnsiToUtf16
(
PCSTR
ansiSrc
)
{
wchar_t
*
pWide
;
int
iUnicodeLen
=
::
MultiByteToWideChar
(
CP_ACP
,
0
,
ansiSrc
,
-
1
,
NULL
,
0
);
pWide
=
new
wchar_t
[
iUnicodeLen
+
1
];
memset
(
pWide
,
0
,
(
iUnicodeLen
+
1
)
*
sizeof
(
wchar_t
)
);
::
MultiByteToWideChar
(
CP_ACP
,
0
,
ansiSrc
,
-
1
,
(
LPWSTR
)
pWide
,
iUnicodeLen
);
int
iUnicodeLen
=
::
MultiByteToWideChar
(
CP_ACP
,
0
,
ansiSrc
,
-
1
,
NULL
,
0
);
pWide
=
new
wchar_t
[
iUnicodeLen
+
1
];
memset
(
pWide
,
0
,
(
iUnicodeLen
+
1
)
*
sizeof
(
wchar_t
)
);
::
MultiByteToWideChar
(
CP_ACP
,
0
,
ansiSrc
,
-
1
,
(
LPWSTR
)
pWide
,
iUnicodeLen
);
return
pWide
;
}
__forceinline
BOOL
AnsiToUtf16Array
(
PCSTR
ansiSrc
,
wchar_t
*
warr
,
int
warr_len
)
{
int
iUnicodeLen
=
::
MultiByteToWideChar
(
CP_ACP
,
0
,
ansiSrc
,
-
1
,
NULL
,
0
);
if
(
warr_len
>=
iUnicodeLen
)
{
memset
(
warr
,
0
,
(
iUnicodeLen
+
1
)
*
sizeof
(
wchar_t
)
);
::
MultiByteToWideChar
(
CP_ACP
,
0
,
ansiSrc
,
-
1
,
(
LPWSTR
)
warr
,
iUnicodeLen
);
int
iUnicodeLen
=
::
MultiByteToWideChar
(
CP_ACP
,
0
,
ansiSrc
,
-
1
,
NULL
,
0
);
if
(
warr_len
>=
iUnicodeLen
)
{
memset
(
warr
,
0
,
(
iUnicodeLen
+
1
)
*
sizeof
(
wchar_t
)
);
::
MultiByteToWideChar
(
CP_ACP
,
0
,
ansiSrc
,
-
1
,
(
LPWSTR
)
warr
,
iUnicodeLen
);
return
TRUE
;
}
return
FALSE
;
...
...
@@ -225,11 +220,11 @@ __forceinline BOOL AnsiToUtf16Array(PCSTR ansiSrc, wchar_t* warr, int warr_len)
__forceinline
wchar_t
*
Utf8ToUtf16
(
PCSTR
ansiSrc
)
{
wchar_t
*
pWide
;
int
iUnicodeLen
=
::
MultiByteToWideChar
(
CP_UTF8
,
0
,
ansiSrc
,
-
1
,
NULL
,
0
);
pWide
=
new
wchar_t
[
iUnicodeLen
+
1
];
memset
(
pWide
,
0
,
(
iUnicodeLen
+
1
)
*
sizeof
(
wchar_t
)
);
::
MultiByteToWideChar
(
CP_UTF8
,
0
,
ansiSrc
,
-
1
,
(
LPWSTR
)
pWide
,
iUnicodeLen
);
int
iUnicodeLen
=
::
MultiByteToWideChar
(
CP_UTF8
,
0
,
ansiSrc
,
-
1
,
NULL
,
0
);
pWide
=
new
wchar_t
[
iUnicodeLen
+
1
];
memset
(
pWide
,
0
,
(
iUnicodeLen
+
1
)
*
sizeof
(
wchar_t
)
);
::
MultiByteToWideChar
(
CP_UTF8
,
0
,
ansiSrc
,
-
1
,
(
LPWSTR
)
pWide
,
iUnicodeLen
);
return
pWide
;
}
...
...
@@ -243,37 +238,37 @@ __inline const char* Utf16ToUtf8(const wchar_t* utf16, int& out_len)
}
__inline
const
char
*
Utf16ToGbk
(
const
wchar_t
*
utf16
)
{
//WideCharToMultiByte(CP_GBK)
}
//
__inline const char* Utf16ToGbk(const wchar_t* utf16)
//
{
//
//WideCharToMultiByte(CP_GBK)
//
}
/*
__forceinline CString GetFileVersion()
{
int iVerInfoSize;
char *pBuf;
CString asVer= _T("");
VS_FIXEDFILEINFO *pVsInfo;
unsigned int iFileInfoSize = sizeof(VS_FIXEDFILEINFO);
TCHAR fileName[MAX_PATH];
GetModuleFileName(NULL, fileName, MAX_PATH);
iVerInfoSize = GetFileVersionInfoSize(fileName, NULL);
if(iVerInfoSize != 0){
pBuf = new char[iVerInfoSize];
if(GetFileVersionInfo(fileName, 0, iVerInfoSize, pBuf)){
if(VerQueryValue(pBuf, _T("//"), (void**)&pVsInfo, &iFileInfoSize)){
asVer.Format(_T("%d.%d.%d.%d"),
HIWORD(pVsInfo->dwFileVersionMS),
LOWORD(pVsInfo->dwFileVersionMS),
HIWORD(pVsInfo->dwFileVersionLS),
LOWORD(pVsInfo->dwFileVersionLS));
}
}
delete pBuf;
}
return asVer;
}
{
int iVerInfoSize;
char *pBuf;
CString asVer= _T("");
VS_FIXEDFILEINFO *pVsInfo;
unsigned int iFileInfoSize = sizeof(VS_FIXEDFILEINFO);
TCHAR fileName[MAX_PATH];
GetModuleFileName(NULL, fileName, MAX_PATH);
iVerInfoSize = GetFileVersionInfoSize(fileName, NULL);
if(iVerInfoSize != 0){
pBuf = new char[iVerInfoSize];
if(GetFileVersionInfo(fileName, 0, iVerInfoSize, pBuf)){
if(VerQueryValue(pBuf, _T("//"), (void**)&pVsInfo, &iFileInfoSize)){
asVer.Format(_T("%d.%d.%d.%d"),
HIWORD(pVsInfo->dwFileVersionMS),
LOWORD(pVsInfo->dwFileVersionMS),
HIWORD(pVsInfo->dwFileVersionLS),
LOWORD(pVsInfo->dwFileVersionLS));
}
}
delete pBuf;
}
return asVer;
}
*/
\ No newline at end of file
initsock.h
0 → 100644
View file @
19de8857
//////////////////////////////////////////////////////////
// initsock.hļ
#include <winsock2.h>
#pragma comment(lib, "WS2_32") // ӵWS2_32.lib
class
CInitSock
{
public
:
CInitSock
(
BYTE
minorVer
=
2
,
BYTE
majorVer
=
2
)
{
// ʼWS2_32.dll
WSADATA
wsaData
;
WORD
sockVersion
=
MAKEWORD
(
minorVer
,
majorVer
);
if
(
::
WSAStartup
(
sockVersion
,
&
wsaData
)
!=
0
)
{
ExitProcess
(
0
);
}
}
~
CInitSock
()
{
::
WSACleanup
();
}
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment