mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
修复test_player windows编译错误
This commit is contained in:
parent
2d16e39445
commit
20ca0f76cd
@ -44,6 +44,9 @@ foreach(TEST_SRC ${TEST_SRC_LIST})
|
||||
target_link_libraries(${TEST_EXE_NAME} ${LINK_LIB_LIST})
|
||||
endforeach()
|
||||
|
||||
if(MSVC)
|
||||
set_target_properties(test_player PROPERTIES LINK_FLAGS "/SAFESEH:NO /SUBSYSTEM:WINDOWS" )
|
||||
endif(MSVC)
|
||||
|
||||
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include "Util/util.h"
|
||||
#include "Util/logger.h"
|
||||
#include <iostream>
|
||||
@ -40,11 +39,74 @@ using namespace std;
|
||||
using namespace toolkit;
|
||||
using namespace mediakit;
|
||||
|
||||
std::string Utf8ToGbk(std::string src_str)
|
||||
{
|
||||
#ifdef WIN32
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, src_str.c_str(), -1, NULL, 0);
|
||||
wchar_t* wszGBK = new wchar_t[len + 1];
|
||||
memset(wszGBK, 0, len * 2 + 2);
|
||||
MultiByteToWideChar(CP_UTF8, 0, src_str.c_str(), -1, wszGBK, len);
|
||||
len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL);
|
||||
char* szGBK = new char[len + 1];
|
||||
memset(szGBK, 0, len + 1);
|
||||
WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, szGBK, len, NULL, NULL);
|
||||
string strTemp(szGBK);
|
||||
if (wszGBK) delete[] wszGBK;
|
||||
if (szGBK) delete[] szGBK;
|
||||
return strTemp;
|
||||
#else
|
||||
return src_str;
|
||||
#endif
|
||||
}
|
||||
|
||||
class log4Channel : public LogChannel {
|
||||
public:
|
||||
log4Channel(const string &name = "log4Channel", LogLevel level = LTrace) :LogChannel(name, level)
|
||||
{
|
||||
|
||||
}
|
||||
~log4Channel() {}
|
||||
void write(const Logger &logger, const LogContextPtr &logContext) override
|
||||
{
|
||||
if (_level > logContext->_level) {
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s %s\n", logContext->_function, Utf8ToGbk(logContext->str()).c_str());
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef WIN32
|
||||
#include <TCHAR.h>
|
||||
|
||||
extern int __argc;
|
||||
extern TCHAR** __targv;
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstanc, LPSTR lpCmdLine, int nShowCmd) {
|
||||
int argc = __argc;
|
||||
char **argv = __targv;
|
||||
|
||||
//1. 首先调用AllocConsole创建一个控制台窗口
|
||||
AllocConsole();
|
||||
|
||||
//2. 但此时调用cout或者printf都不能正常输出文字到窗口(包括输入流cin和scanf), 所以需要如下重定向输入输出流:
|
||||
FILE* stream;
|
||||
freopen_s(&stream, "CON", "r", stdin);//重定向输入流
|
||||
freopen_s(&stream, "CON", "w", stdout);//重定向输入流
|
||||
|
||||
//3. 如果我们需要用到控制台窗口句柄,可以调用FindWindow取得:
|
||||
HWND _consoleHwnd;
|
||||
SetConsoleTitleA("test_player");//设置窗口名
|
||||
#else
|
||||
#include <unistd.h>
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
#endif
|
||||
|
||||
//设置退出信号处理函数
|
||||
signal(SIGINT, [](int) { SDLDisplayerHelper::Instance().shutdown(); });
|
||||
//设置日志
|
||||
Logger::Instance().add(std::make_shared<ConsoleChannel>());
|
||||
Logger::Instance().add(std::make_shared<log4Channel>());
|
||||
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
|
||||
|
||||
if (argc != 3) {
|
||||
|
Loading…
Reference in New Issue
Block a user