win32.h

来自「本人收集整理的一份c/c++跨平台网络库」· C头文件 代码 · 共 56 行

H
56
字号
#ifndef UTILS_BASE_WIN32_H_#define UTILS_BASE_WIN32_H_#include <winsock2.h>#include <windows.h>#include <malloc.h>#include <string>namespace utils_base {///////////////////////////////////////////////////////////////////////////////inline std::wstring ToUtf16(const std::string& str) {  int len16 = ::MultiByteToWideChar(CP_UTF8, 0, str.data(), (int)str.length(),                                    NULL, 0);  wchar_t *ws = static_cast<wchar_t*>(_alloca(len16 * sizeof(wchar_t)));  ::MultiByteToWideChar(CP_UTF8, 0, str.data(), (int)str.length(), ws, len16);  std::wstring result(ws, len16);  return result;}inline std::string ToUtf8(const std::wstring& wstr) {  int len8 = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.length(),                                   NULL, 0, NULL, NULL);  char* ns = static_cast<char*>(_alloca(len8));  ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.length(),                        ns, len8, NULL, NULL);  std::string result(ns, len8);  return result;}// Convert FILETIME to time_tinline void FileTimeToUnixTime(const FILETIME& ft, time_t* ut)/// yzxu_alter{	SYSTEMTIME systime;	if (FileTimeToSystemTime(&ft, &systime))		*ut = (time_t)systime.wMilliseconds;	else		*ut = (time_t)0;}// Convert time_t to FILETIMEinline void UnixTimeToFileTime(const time_t& ut, FILETIME * ft)/// yzxu_alter{	SYSTEMTIME systime;	systime.wMilliseconds = (WORD)ut;	SystemTimeToFileTime(&systime, ft);}///////////////////////////////////////////////////////////////////////////////}  // namespace utils_base#endif  // UTILS_BASE_WIN32_H__

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?