2022-9-2 01:27:03
This commit is contained in:
56
src/utils.h
Normal file
56
src/utils.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef utils_h__
|
||||
#define utils_h__
|
||||
#include <string>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#define BUFFCOUNT (3196)
|
||||
#define SET_TEXTW(X) L#X
|
||||
#define SET_TEXTA(X) #X
|
||||
|
||||
|
||||
namespace Util
|
||||
{
|
||||
/**
|
||||
* @brief 到16进制Hex文本
|
||||
* @param buf
|
||||
* @param len
|
||||
* @param tok
|
||||
* @return
|
||||
*/
|
||||
static std::string ToHexString(const unsigned char* buf, int len, std::string tok = " ")
|
||||
{
|
||||
std::string output;
|
||||
char temp[8];
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
memset(temp, 0, sizeof(temp));
|
||||
snprintf(temp, sizeof(temp), "%.2X", buf[i]);
|
||||
output.append(temp, 2);
|
||||
output.append(tok);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
static void _Log(const char* formatstring, ...)
|
||||
{
|
||||
int nSize = 0;
|
||||
char buff[BUFFCOUNT];
|
||||
memset(buff, 0, sizeof(buff));
|
||||
va_list args;
|
||||
va_start(args, formatstring);
|
||||
nSize = vsnprintf(buff, sizeof(buff), formatstring, args);
|
||||
va_end(args);
|
||||
char szPrINT32[BUFFCOUNT + 50] = { 0 };
|
||||
sprintf(szPrINT32, "[DNF_PROJECT] %s \n", buff);//wsprintfA
|
||||
printf(szPrINT32);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#define LOG(format,...) Util::_Log(format,##__VA_ARGS__)
|
||||
|
||||
|
||||
#endif // utils_h__
|
||||
Reference in New Issue
Block a user