|
@@ -13,6 +13,11 @@ using namespace std;
|
|
#include <Iphlpapi.h>
|
|
#include <Iphlpapi.h>
|
|
#pragma comment(lib,"Iphlpapi.lib") //需要添加Iphlpapi.lib库
|
|
#pragma comment(lib,"Iphlpapi.lib") //需要添加Iphlpapi.lib库
|
|
|
|
|
|
|
|
+#define K1 1024
|
|
|
|
+#define K2 2048
|
|
|
|
+#define K4 4096
|
|
|
|
+#define K8 8192
|
|
|
|
+
|
|
namespace GLOBAL
|
|
namespace GLOBAL
|
|
{
|
|
{
|
|
CDataImpl g_db;
|
|
CDataImpl g_db;
|
|
@@ -1425,4 +1430,76 @@ end:
|
|
|
|
|
|
return strIPAddress;
|
|
return strIPAddress;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ std::string wcs2mbs(LPCTSTR wcs)
|
|
|
|
+ {
|
|
|
|
+ if (wcs)
|
|
|
|
+ {
|
|
|
|
+ // 计算待转换的字节数
|
|
|
|
+ size_t count = wcstombs(NULL, wcs, 0);
|
|
|
|
+ if (count <= K1) // 1k;
|
|
|
|
+ {
|
|
|
|
+ char szValue[K1] = { 0 };
|
|
|
|
+ wcstombs(szValue, wcs, count);
|
|
|
|
+ return std::string(szValue);
|
|
|
|
+ }
|
|
|
|
+ else if (count <= K2) // 2k;
|
|
|
|
+ {
|
|
|
|
+ char szValue[K2] = { 0 };
|
|
|
|
+ wcstombs(szValue, wcs, count);
|
|
|
|
+ return std::string(szValue);
|
|
|
|
+ }
|
|
|
|
+ else if (count <= K4) // 4k;
|
|
|
|
+ {
|
|
|
|
+ char szValue[K4] = { 0 };
|
|
|
|
+ wcstombs(szValue, wcs, count);
|
|
|
|
+ return std::string(szValue);
|
|
|
|
+ }
|
|
|
|
+ else if (count <= K8) // 8k;
|
|
|
|
+ {
|
|
|
|
+ char szValue[K8] = { 0 };
|
|
|
|
+ wcstombs(szValue, wcs, count);
|
|
|
|
+ return std::string(szValue);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 超过8k;
|
|
|
|
+ return std::string();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ std::wstring mbs2wcs(LPCSTR mbs)
|
|
|
|
+ {
|
|
|
|
+ if (mbs)
|
|
|
|
+ {
|
|
|
|
+ // 计算待转换的字节数
|
|
|
|
+ size_t count = mbstowcs(NULL, mbs, 0);
|
|
|
|
+ if (count <= K1) // 1k;
|
|
|
|
+ {
|
|
|
|
+ wchar_t szValue[K1] = { 0 };
|
|
|
|
+ mbstowcs(szValue, mbs, count);
|
|
|
|
+ return std::wstring(szValue);
|
|
|
|
+ }
|
|
|
|
+ else if (count <= K2) // 2k;
|
|
|
|
+ {
|
|
|
|
+ wchar_t szValue[K2] = { 0 };
|
|
|
|
+ mbstowcs(szValue, mbs, count);
|
|
|
|
+ return std::wstring(szValue);
|
|
|
|
+ }
|
|
|
|
+ else if (count <= K4) // 4k;
|
|
|
|
+ {
|
|
|
|
+ wchar_t szValue[K4] = { 0 };
|
|
|
|
+ mbstowcs(szValue, mbs, count);
|
|
|
|
+ return std::wstring(szValue);
|
|
|
|
+ }
|
|
|
|
+ else if (count <= K8) // 8k;
|
|
|
|
+ {
|
|
|
|
+ wchar_t szValue[K8] = { 0 };
|
|
|
|
+ mbstowcs(szValue, mbs, count);
|
|
|
|
+ return std::wstring(szValue);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 超过8k;
|
|
|
|
+ return std::wstring();
|
|
|
|
+ }
|
|
};
|
|
};
|