diff --git a/base/base.vcxproj b/base/base.vcxproj index ff11ae99..5b2a6f2d 100644 --- a/base/base.vcxproj +++ b/base/base.vcxproj @@ -143,7 +143,7 @@ StaticLibrary true Unicode - v120_xp + v142 StaticLibrary diff --git a/examples/cef/cef.vcxproj b/examples/cef/cef.vcxproj index 7be0a182..94b2be7c 100644 --- a/examples/cef/cef.vcxproj +++ b/examples/cef/cef.vcxproj @@ -42,7 +42,7 @@ Application true - v120_xp + v142 Unicode @@ -131,6 +131,7 @@ Windows true nim_libcef.dll + nim_libcef.lib;%(AdditionalDependencies) diff --git a/examples/examples.sln b/examples/examples.sln index c78aa6fb..97e6cd7d 100644 --- a/examples/examples.sln +++ b/examples/examples.sln @@ -31,8 +31,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ui_components", "..\ui_comp EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "proto_debuger", "proto_debuger\proto_debuger.vcxproj", "{6D78D8B7-1617-4ED4-B155-94369FC3E73C}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "catch_test", "catch_test\catch_test.vcxproj", "{91850193-0E5E-4983-9D11-F9875805D91E}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -135,14 +133,6 @@ Global {6D78D8B7-1617-4ED4-B155-94369FC3E73C}.Release|Win32.Build.0 = Release|Win32 {6D78D8B7-1617-4ED4-B155-94369FC3E73C}.Release|x64.ActiveCfg = Release|x64 {6D78D8B7-1617-4ED4-B155-94369FC3E73C}.Release|x64.Build.0 = Release|x64 - {91850193-0E5E-4983-9D11-F9875805D91E}.Debug|Win32.ActiveCfg = Debug|Win32 - {91850193-0E5E-4983-9D11-F9875805D91E}.Debug|Win32.Build.0 = Debug|Win32 - {91850193-0E5E-4983-9D11-F9875805D91E}.Debug|x64.ActiveCfg = Debug|x64 - {91850193-0E5E-4983-9D11-F9875805D91E}.Debug|x64.Build.0 = Debug|x64 - {91850193-0E5E-4983-9D11-F9875805D91E}.Release|Win32.ActiveCfg = Release|Win32 - {91850193-0E5E-4983-9D11-F9875805D91E}.Release|Win32.Build.0 = Release|Win32 - {91850193-0E5E-4983-9D11-F9875805D91E}.Release|x64.ActiveCfg = Release|x64 - {91850193-0E5E-4983-9D11-F9875805D91E}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -156,7 +146,6 @@ Global {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9} = {1DA0A8E2-5832-42FC-83F7-2CDCAD379C90} {8BD95440-9000-4745-8011-27DD553EF06F} = {B2087994-3DF6-4A57-B8C6-6F744520D7FA} {E35589C6-9509-4116-996F-1D045C2DACAE} = {B2087994-3DF6-4A57-B8C6-6F744520D7FA} - {91850193-0E5E-4983-9D11-F9875805D91E} = {B2087994-3DF6-4A57-B8C6-6F744520D7FA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {68CA0970-4242-4E4F-94D2-C19760FCA05D} diff --git a/examples/multi_browser/multi_browser.vcxproj b/examples/multi_browser/multi_browser.vcxproj index fccfc6b2..2d88c9ad 100644 --- a/examples/multi_browser/multi_browser.vcxproj +++ b/examples/multi_browser/multi_browser.vcxproj @@ -39,7 +39,7 @@ Unicode - v120_xp + v142 v120_xp diff --git a/examples/proto_debuger/base_form.cpp b/examples/proto_debuger/base_form.cpp index c984a5b3..35d881dc 100644 --- a/examples/proto_debuger/base_form.cpp +++ b/examples/proto_debuger/base_form.cpp @@ -1,5 +1,6 @@ #include "base_form.h" #include "serial_port.h" +#include "utils.h" const std::wstring BasicForm::kClassName = L"Basic"; @@ -61,9 +62,58 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) //this->Paint(); } + if (uMsg == WM_USER_POS_CHANGED) { } + + if (uMsg == WM_ADD_TCPCLIENT_MONITOR) { + TcpClientInfo* info = (TcpClientInfo*)wParam; + TcpClientLibevent* cli = (TcpClientLibevent*)lParam; + ui::TreeNode* node = new ui::TreeNode; + node->SetText(info->ip); + node->SetClass(L"listitem"); + node->SetFixedHeight(20); + node->SetMargin({ 20, 0, 0, 0 }); + mMonitor->GetRootNode()->GetChildNode(1)->AddChildNode(node); + + if (mTcpClientForm.find(info->socket_fd) == mTcpClientForm.end()) { + auto form = new TcpClientForm(wstring2string(info->ip),info->port, cli); + form->SetChildLayoutXML(L"basic/tcp_form.xml"); + form->SetName(info->ip); + form->SetVisible(false); + mTcpClientForm[info->socket_fd] = form; + if (!mRightSide->Add(form)) + printf("erroer 1"); + } + node->AttachAllEvents([this](ui::EventArgs* ev) { + if (ui::EventType::kEventSelect == ev->Type) { + wprintf(L"%s\r\n", dynamic_cast (ev->pSender)->GetText().c_str()); + printf("GetCurSel %d\r\n", mRightSide->GetCurSel()); + //TcpClientForm* p = mTcpClientForm[dynamic_cast (ev->pSender)->GetText()]; + /* + if (p != nullptr) { + p->SetAutoDestroy(true); + if (mRightShow != nullptr) { + mRightShow->SetVisible(false); + p->SetVisible(true); + mRightShow = p; + mRightSide->SelectItem(p->GetName()); + + } + else { + p->SetVisible(true); + + mRightSide->SelectItem(p->GetName()); + mRightShow = p; + } + }*/ + } + return true; + }); + } + + if (uMsg == WM_ADD_UART_MONITOR) { printf("add monitor"); UartInfo* p = (UartInfo*)wParam; diff --git a/examples/proto_debuger/base_form.h b/examples/proto_debuger/base_form.h index 5d43ae85..421710fc 100644 --- a/examples/proto_debuger/base_form.h +++ b/examples/proto_debuger/base_form.h @@ -16,11 +16,13 @@ #include "ui_components/ui_components.h" #include "new_monitor_form.h" #include "uart_process.h" +#include "tcp_client_form.h" #include #include #define WM_USER_POS_CHANGED (WM_USER + 2) #define WM_ADD_UART_MONITOR (WM_USER + 3) +#define WM_ADD_TCPCLIENT_MONITOR (WM_USER + 4) class BasicForm : public ui::WindowImplBase @@ -55,5 +57,7 @@ private: ui::TabBox *mRightSide; ui::TreeView *mMonitor; std::map mUartForm; + std::map mTcpClientForm; + ui::Control* mRightShow; }; diff --git a/examples/proto_debuger/main.cpp b/examples/proto_debuger/main.cpp index 5001e8f2..cac8f399 100644 --- a/examples/proto_debuger/main.cpp +++ b/examples/proto_debuger/main.cpp @@ -16,6 +16,34 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { + +#ifdef WIN32 + WORD wdVersion = MAKEWORD(2, 2);//定义自己需要的网络库版本,这里是2.2 + WSADATA wdSockMsg;//这是一个结构体 + int nRes = WSAStartup(wdVersion, &wdSockMsg);//打开一个套接字 + if (0 != nRes) { + switch (nRes) { + case WSASYSNOTREADY: + printf("check your library"); + break; + case WSAVERNOTSUPPORTED: + printf("need updated"); + break; + case WSAEINPROGRESS: + printf("need reboot"); + break; + case WSAEPROCLIM: + printf("sdfsdfsa"); + break; + } + } + if (2 != HIBYTE(wdSockMsg.wVersion) || 2 != LOBYTE(wdSockMsg.wVersion)) { + printf("WSACleanup"); + WSACleanup(); + return 0; + } +#endif + AllocConsole(); freopen("CONOUT$", "w", stdout); diff --git a/examples/proto_debuger/new_monitor_form.cpp b/examples/proto_debuger/new_monitor_form.cpp index 5d263e0c..8506657e 100644 --- a/examples/proto_debuger/new_monitor_form.cpp +++ b/examples/proto_debuger/new_monitor_form.cpp @@ -8,6 +8,9 @@ #include #include "serial_port.h" #include "base_form.h" +#include "tcp_client.h" +#include "utils.h" +#include using namespace std; @@ -60,6 +63,7 @@ vector EnumPortsWdm() NewMonitorForm::NewMonitorForm(ui::Window* parent) { m_parent = parent; + m_tcp_client = nullptr; } NewMonitorForm::~NewMonitorForm() @@ -128,7 +132,24 @@ void NewMonitorForm::InitWindow() } } if (m_combo_type->GetText() == L"tcp client") { - + wprintf(L"%s\r\n",m_ip_select->GetText().c_str()); + wprintf(L"%s\r\n", m_port_select->GetText().c_str()); + int port = atoi(wstring2string(m_port_select->GetText()).c_str()); + m_tcp_client = new TcpClientLibevent(wstring2string(m_ip_select->GetText()), port,nullptr); + if (m_tcp_client->Connected()) { + printf("连接成功\r\n"); + TcpClientInfo* p = new TcpClientInfo; + p->ip = m_port_select->GetText(); + p->port = port; + p->socket_fd = m_tcp_client->SocketFd(); + + auto succ = ::PostMessage(m_parent->GetHWND(), + WM_ADD_TCPCLIENT_MONITOR, (WPARAM)p, (LPARAM)m_tcp_client); + if (!succ) { + printf("postmessage error :%d\r\n", GetLastError()); + } + } + } if (m_combo_type->GetText() == L"tcp server") { diff --git a/examples/proto_debuger/new_monitor_form.h b/examples/proto_debuger/new_monitor_form.h index e12431ab..de6db068 100644 --- a/examples/proto_debuger/new_monitor_form.h +++ b/examples/proto_debuger/new_monitor_form.h @@ -9,9 +9,9 @@ #include "base/base.h" -// duilib #include "duilib/UIlib.h" #include "ui_components/ui_components.h" +#include "tcp_client.h" class NewMonitorForm : public ui::WindowImplBase @@ -52,6 +52,6 @@ private: ui::Combo* m_combo_type; ui::Window* m_parent; - + TcpClientLibevent* m_tcp_client; }; diff --git a/examples/proto_debuger/proto_debuger.vcxproj b/examples/proto_debuger/proto_debuger.vcxproj index 05d967fe..d3796941 100644 --- a/examples/proto_debuger/proto_debuger.vcxproj +++ b/examples/proto_debuger/proto_debuger.vcxproj @@ -81,7 +81,7 @@ true - $(VC_IncludePath);$(WindowsSDK_IncludePath);..\..\;$(ProjectDir)third\include\libevent\include + $(VC_IncludePath);$(WindowsSDK_IncludePath);..\..\;$(ProjectDir)third\include\libevent\include;$(ProjectDir) $(ReferencePath) $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(ProjectDir)third\lib @@ -167,7 +167,9 @@ + + @@ -175,13 +177,16 @@ + + + diff --git a/examples/proto_debuger/proto_debuger.vcxproj.filters b/examples/proto_debuger/proto_debuger.vcxproj.filters index 14b59c75..83339ca8 100644 --- a/examples/proto_debuger/proto_debuger.vcxproj.filters +++ b/examples/proto_debuger/proto_debuger.vcxproj.filters @@ -30,6 +30,15 @@ 婧愭枃浠 + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + @@ -50,6 +59,12 @@ 澶存枃浠 + + 澶存枃浠 + + + 澶存枃浠 + @@ -64,6 +79,9 @@ 璧勬簮鏂囦欢 + + 璧勬簮鏂囦欢 + diff --git a/examples/proto_debuger/serial_port.h b/examples/proto_debuger/serial_port.h index a748b585..91b8019c 100644 --- a/examples/proto_debuger/serial_port.h +++ b/examples/proto_debuger/serial_port.h @@ -17,6 +17,13 @@ typedef struct{ uint8_t flow_control; }UartInfo; +typedef struct { + wstring ip; + uint32_t port; + uint32_t socket_fd; +}TcpClientInfo; + + class SerialPort { diff --git a/examples/proto_debuger/tcp_client.cpp b/examples/proto_debuger/tcp_client.cpp index 2dbe2bb5..122ebc64 100644 --- a/examples/proto_debuger/tcp_client.cpp +++ b/examples/proto_debuger/tcp_client.cpp @@ -15,8 +15,6 @@ static void conn_eventcb(struct bufferevent *, short, void *); void delay(int ms); int ThreadRun(TcpClientLibevent *p); - - void conn_writecb(struct bufferevent *bev, void *user_data) { @@ -25,7 +23,6 @@ void conn_writecb(struct bufferevent *bev, void *user_data) // 杩愯绾跨▼ int ThreadRun(TcpClientLibevent *p) { if (nullptr != p) { - p->mStatus = TcpClientLibevent::UNCONNECTED; int ret = p->Dispatch(); if (0 > ret){ } @@ -67,6 +64,9 @@ void conn_eventcb(struct bufferevent *bev, short events, void *user_data) { TcpClientLibevent *p; p = (TcpClientLibevent *)user_data; + if (p == nullptr) { + return; + } if (events & BEV_EVENT_EOF) { if (nullptr != p->mObserver) p->mObserver->OnDisConnected(); @@ -79,13 +79,13 @@ void conn_eventcb(struct bufferevent *bev, short events, void *user_data) if (nullptr != p->mObserver) p->mObserver->OnDisConnected(); p->mStatus = TcpClientLibevent::FAIL; - } + } else if (events & BEV_EVENT_CONNECTED) { - printf("Connect succeed\n"); + p->mSocketFD = (uint64_t)event_get_fd(&(bev->ev_read)); + printf("Connect succeed %d %d \n", p->mSocketFD, event_get_fd(&(bev->ev_write))); //瀹㈡埛绔摼鎺ユ垚鍔熷悗锛岀粰鏈嶅姟鍣ㄥ彂閫佺涓鏉℃秷鎭 if (nullptr != p->mObserver) p->mObserver->OnConnected(); - if (p != nullptr) p->mStatus = TcpClientLibevent::UNCONNECTED; return; } @@ -116,7 +116,6 @@ TcpClientLibevent::TcpClientLibevent(std::string addrinfo, int port, TcpClientLi mSrv.sin_family = AF_INET; #endif mSrv.sin_port = htons(port); - mBase = event_base_new(); if (!mBase) { @@ -131,10 +130,12 @@ TcpClientLibevent::TcpClientLibevent(std::string addrinfo, int port, TcpClientLi ConnectServer(); this->mThread = new thread(ThreadRun,this); this->mObserver = p; + mByteRecv = 0; + mByteSend = 0; } int TcpClientLibevent::ConnectServer() { - printf("connect server\r\n"); + printf("server conecting...\r\n"); evthread_make_base_notifiable(mBase); bev = bufferevent_socket_new(mBase, -1, BEV_OPT_CLOSE_ON_FREE | BEV_OPT_THREADSAFE); @@ -174,3 +175,8 @@ int TcpClientLibevent::Close() { event_base_free(mBase); return 0; } + +uint64_t TcpClientLibevent::SocketFd() +{ + return mSocketFD; +} diff --git a/examples/proto_debuger/tcp_client.h b/examples/proto_debuger/tcp_client.h index e5397e6d..2acdcf82 100644 --- a/examples/proto_debuger/tcp_client.h +++ b/examples/proto_debuger/tcp_client.h @@ -1,13 +1,13 @@ // // Created by 29019 on 2020/4/18. // - -#ifndef GENERAL_TCPCLIENT_H -#define GENERAL_TCPCLIENT_H +#pragma once #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0500 #endif + + #ifdef linux #include #include @@ -17,15 +17,21 @@ extern "C"{ #include "event2/bufferevent.h" + #include "event2/bufferevent_struct.h" #include "event2/buffer.h" #include "event2/listener.h" #include "event2/util.h" #include "event2/event.h" #include "event2/thread.h" + /* For int types. */ + #include + /* For struct event */ + #include + }; + #include #include -// #include "PackageReceiver.h" #include #include using namespace std; @@ -33,40 +39,50 @@ using namespace std; class TcpClientLibevent { public: typedef enum { - UNCONNECTED, // 鏈繛鎺 - CONNECTED, //宸茬粡杩炴帴 - FAIL, // 杩炴帴澶辫触 + UNCONNECTED, // 鏈繛鎺 + CONNECTED, //宸茬粡杩炴帴 + FAIL, // 杩炴帴澶辫触 }Status; - class TcpClientObserver{ + + class TcpClientObserver { public: - virtual ~TcpClientObserver(){return;} + virtual ~TcpClientObserver() { return; } mutex mMux; virtual void OnConnected() { return; }; virtual void OnDisConnected() { return; }; - virtual void OnData(uint8_t *dat,uint64_t len){return;}; - virtual void OnClose(){return;}; + virtual void OnData(uint8_t* dat, uint64_t len) { return; }; + virtual void OnClose() { return; }; }; - TcpClientLibevent(std::string addrinfo,int port, TcpClientObserver *p); - ~TcpClientLibevent(){ + TcpClientLibevent(std::string addrinfo, int port, TcpClientObserver* p); + ~TcpClientLibevent() { event_base_free(mBase); }; + + friend void conn_eventcb(struct bufferevent*, short, void*); + int ConnectServer(); bool Connected(); int Dispatch(); - int OnTCPPackage(uint8_t *, uint16_t); + int OnTCPPackage(uint8_t*, uint16_t); int SetReconnect(bool); int SetObserver(TcpClientObserver*); int Close(); + uint64_t SocketFd(); + Status mStatus; - TcpClientObserver *mObserver; + TcpClientObserver* mObserver; private: bool mReConnect = false; - int sendData(void*,size_t); - struct event_base *mBase; + int sendData(void*, size_t); + struct event_base* mBase; struct bufferevent* bev; struct sockaddr_in mSrv; - std::thread *mThread; - mutex mLock; + std::thread* mThread; + mutex mLock; // 浜掓枼閿 + uint64_t mByteSend; // 鍙戦佸瓧鑺傛暟 + uint64_t mByteRecv; // 鎺ユ敹瀛楄妭鏁 + evutil_socket_t mSocketFD; // 鎿嶄綔绯荤粺鍘熺敓socket + }; -#endif //GENERAL_TCPCLIENT_H + diff --git a/examples/proto_debuger/tcp_client_form.cpp b/examples/proto_debuger/tcp_client_form.cpp new file mode 100644 index 00000000..bbe55daf --- /dev/null +++ b/examples/proto_debuger/tcp_client_form.cpp @@ -0,0 +1,24 @@ +#include "tcp_client_form.h" + +TcpClientForm::TcpClientForm(std::string url, uint32_t port, TcpClientLibevent* p) +{ + mClient = p; +} + +void TcpClientForm::Init() +{ + ui::Label* m_label_1 = dynamic_cast(FindSubControl(L"uart_info_label")); + ui::RichEdit* m_rich_edit_1 = dynamic_cast(FindSubControl(L"uart_recv_eidt")); + ui::RichEdit* m_rich_edit_2 = dynamic_cast(FindSubControl(L"lua_script")); + ui::RichEdit* m_rich_edit_3 = dynamic_cast(FindSubControl(L"uart_send_edit")); + ui::Button* m_button_1 = dynamic_cast(FindSubControl(L"btn_send_data")); + ui::CheckBox* m_check_box_1 = dynamic_cast(FindSubControl(L"check_new_line")); + ui::CheckBox* m_check_box_2 = dynamic_cast(FindSubControl(L"check_time_send")); + ui::CheckBox* m_check_box_3 = dynamic_cast(FindSubControl(L"check_hex_send")); + ui::CheckBox* m_check_box_4 = dynamic_cast(FindSubControl(L"check_hex_recv")); + +} + +void TcpClientForm::HandleMessage(ui::EventArgs& msg) +{ +} diff --git a/examples/proto_debuger/tcp_client_form.h b/examples/proto_debuger/tcp_client_form.h new file mode 100644 index 00000000..ffb62835 --- /dev/null +++ b/examples/proto_debuger/tcp_client_form.h @@ -0,0 +1,38 @@ +#include + +// C runtime header +#include +#include +#include +#include + +// base header +#include "base/base.h" +#include "serial_port.h" +// duilib +#include "duilib/UIlib.h" +#include "tcp_client.h" + +using namespace std; +class TcpClientForm : public ui::ChildBox { +#pragma once + +public: + TcpClientForm(string url, uint32_t port, TcpClientLibevent* p); + virtual void Init() override; + +private: + TcpClientLibevent* mClient; + ui::Label* m_label_1; + ui::RichEdit* m_rich_edit_1; + ui::RichEdit* m_rich_edit_2; + ui::RichEdit* m_rich_edit_3; + ui::Button* m_button_1; + ui::CheckBox* m_check_box_1; + ui::CheckBox* m_check_box_2; + ui::CheckBox* m_check_box_3; + ui::CheckBox* m_check_box_4; + + virtual void HandleMessage(ui::EventArgs& msg); + +}; \ No newline at end of file diff --git a/examples/proto_debuger/uart_process.cpp b/examples/proto_debuger/uart_process.cpp index 0dad0d74..a1e6d7c1 100644 --- a/examples/proto_debuger/uart_process.cpp +++ b/examples/proto_debuger/uart_process.cpp @@ -1,34 +1,5 @@ #include "uart_process.h" - -wstring string2wstring(string str) -{ - wstring result; - //获取缓冲区大小,并申请空间,缓冲区大小按字符计算 - int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), NULL, 0); - TCHAR* buffer = new TCHAR[len + 1]; - //多字节编码转换成宽字节编码 - MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), buffer, len); - buffer[len] = '\0'; //添加字符串结尾 - //删除缓冲区并返回值 - result.append(buffer); - delete[] buffer; - return result; -} - -std::string wstring2string(std::wstring wstr) -{ - std::string result; - //获取缓冲区大小,并申请空间,缓冲区大小事按字节计算的 - int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), NULL, 0, NULL, NULL); - char* buffer = new char[len + 1]; - //宽字节编码转换成多字节编码 - WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), buffer, len, NULL, NULL); - buffer[len] = '\0'; - //删除缓冲区并返回值 - result.append(buffer); - delete[] buffer; - return result; -} +#include "utils.h" UartForm::UartForm(ui::Window* hwnd,std::wstring name, uint32_t baurate, diff --git a/examples/proto_debuger/utils.cpp b/examples/proto_debuger/utils.cpp new file mode 100644 index 00000000..32645e1f --- /dev/null +++ b/examples/proto_debuger/utils.cpp @@ -0,0 +1,32 @@ +#include "utils.h" +#include + +std::wstring string2wstring(std::string str) +{ + std::wstring result; + //获取缓冲区大小,并申请空间,缓冲区大小按字符计算 + int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), NULL, 0); + TCHAR* buffer = new TCHAR[len + 1]; + //多字节编码转换成宽字节编码 + MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), buffer, len); + buffer[len] = '\0'; //添加字符串结尾 + //删除缓冲区并返回值 + result.append(buffer); + delete[] buffer; + return result; +} + +std::string wstring2string(std::wstring wstr) +{ + std::string result; + //获取缓冲区大小,并申请空间,缓冲区大小事按字节计算的 + int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), NULL, 0, NULL, NULL); + char* buffer = new char[len + 1]; + //宽字节编码转换成多字节编码 + WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), buffer, len, NULL, NULL); + buffer[len] = '\0'; + //删除缓冲区并返回值 + result.append(buffer); + delete[] buffer; + return result; +} \ No newline at end of file diff --git a/examples/proto_debuger/utils.h b/examples/proto_debuger/utils.h new file mode 100644 index 00000000..2ff85cd2 --- /dev/null +++ b/examples/proto_debuger/utils.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +std::wstring string2wstring(std::string str); +std::string wstring2string(std::wstring wstr); + +