Commit eb71674e by 刘帅

使用c++11的utf8字符串,要求使用支持c++11的编译器,另外使用静态链接

parent 0d9668ae
...@@ -32,11 +32,11 @@ extern "C" __declspec(dllexport) int __stdcall FMGetResponse(const char* req, ch ...@@ -32,11 +32,11 @@ extern "C" __declspec(dllexport) int __stdcall FMGetResponse(const char* req, ch
//Log("Initialising Winsock..."); //Log("Initialising Winsock...");
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
{ {
MakeError("Error. Startup error: %d. Server: %s, Port: %d", WSAGetLastError(), setting.ip.c_str(), setting.port) MakeError(u8"Error. Startup error: %d. Server: %s, Port: %d", WSAGetLastError(), setting.ip.c_str(), setting.port)
} }
if(isOk && (_socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) if(isOk && (_socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
{ {
MakeError("Could not create socket: %d. Server: %s, Port: %d", WSAGetLastError(), setting.ip.c_str(), setting.port) MakeError(u8"Could not create socket: %d. Server: %s, Port: %d", WSAGetLastError(), setting.ip.c_str(), setting.port)
} }
_server.sin_addr.S_un.S_addr = (ULONG)inet_addr(setting.ip.c_str()); _server.sin_addr.S_un.S_addr = (ULONG)inet_addr(setting.ip.c_str());
...@@ -48,16 +48,16 @@ extern "C" __declspec(dllexport) int __stdcall FMGetResponse(const char* req, ch ...@@ -48,16 +48,16 @@ extern "C" __declspec(dllexport) int __stdcall FMGetResponse(const char* req, ch
if (isOk && connect(_socket, (struct sockaddr *)&_server, sizeof(_server)) < 0) if (isOk && connect(_socket, (struct sockaddr *)&_server, sizeof(_server)) < 0)
{ {
MakeError("Error. connect error: %d. Server: %s, Port: %d", WSAGetLastError(), setting.ip.c_str(), setting.port) MakeError(u8"Error. connect error: %d. Server: %s, Port: %d", WSAGetLastError(), setting.ip.c_str(), setting.port)
} }
//if (isOk && send(_socket, req, strlen(req), 0) < 0) //if (isOk && send(_socket, req, strlen(req), 0) < 0)
if (isOk && Send(_socket, req) < 0) if (isOk && Send(_socket, req) < 0)
{ {
MakeError("Error. Send error: %d. Server: %s, Port: %d", WSAGetLastError(), setting.ip.c_str(), setting.port) MakeError(u8"Error. Send error: %d. Server: %s, Port: %d", WSAGetLastError(), setting.ip.c_str(), setting.port)
} }
if (isOk) { if (isOk) {
LOG() << "Send data: " << req; LOG() << u8"Send data: " << req;
} }
int recv_size = SOCKET_ERROR; int recv_size = SOCKET_ERROR;
...@@ -66,19 +66,19 @@ extern "C" __declspec(dllexport) int __stdcall FMGetResponse(const char* req, ch ...@@ -66,19 +66,19 @@ extern "C" __declspec(dllexport) int __stdcall FMGetResponse(const char* req, ch
memset(rsp, 0, byteSize); memset(rsp, 0, byteSize);
if (isOk && (recv_size = Recv(_socket, rsp, byteSize-1)) == SOCKET_ERROR) if (isOk && (recv_size = Recv(_socket, rsp, byteSize-1)) == SOCKET_ERROR)
{ {
MakeError("Error. Recv error: %d. Server: %s, Port: %d", WSAGetLastError(), setting.ip.c_str(), setting.port) MakeError(u8"Error. Recv error: %d. Server: %s, Port: %d", WSAGetLastError(), setting.ip.c_str(), setting.port)
} else if(recv_size == FMError_ConnectClosed.Code()) { } else if(recv_size == FMError_ConnectClosed.Code()) {
MakeError("Error. %s(%d). Server: %s, Port: %d", FMError_ConnectClosed.MsgCStr(), WSAGetLastError(), setting.ip.c_str(), setting.port) MakeError(u8"Error. %s(%d). Server: %s, Port: %d", FMError_ConnectClosed.MsgCStr(), WSAGetLastError(), setting.ip.c_str(), setting.port)
} else if(recv_size == FMError_IncorrectHeader.Code()) { } else if(recv_size == FMError_IncorrectHeader.Code()) {
MakeError("Error. %s. Server: %s, Port: %d", FMError_IncorrectHeader.MsgCStr(), setting.ip.c_str(), setting.port) MakeError(u8"Error. %s. Server: %s, Port: %d", FMError_IncorrectHeader.MsgCStr(), setting.ip.c_str(), setting.port)
} else if(recv_size == FMError_BufferOverflow.Code()) { } else if(recv_size == FMError_BufferOverflow.Code()) {
MakeError("Error. %s. Server: %s, Port: %d", FMError_BufferOverflow.MsgCStr(), setting.ip.c_str(), setting.port) MakeError(u8"Error. %s. Server: %s, Port: %d", FMError_BufferOverflow.MsgCStr(), setting.ip.c_str(), setting.port)
} }
if (isOk) { if (isOk) {
LOG() << "Recv size: " << recv_size << " Recv data: " << rsp; LOG() << "Recv size: " << recv_size << " Recv data: " << rsp;
} else if (_error.Code() == FM_ERROR_CODE_SOCKET) { } else if (_error.Code() == FM_ERROR_CODE_SOCKET) {
sprintf(ErrorMsg, "{\"statusCode\": 104, \"msg\": \"本地Socket通讯错误(%s).\"}", _error.Msg().c_str()); sprintf(ErrorMsg, u8"{\"statusCode\": 104, \"msg\": \"本地Socket通讯错误(%s).\"}", _error.Msg().c_str());
strcpy(rsp, ErrorMsg); strcpy(rsp, ErrorMsg);
} }
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
...@@ -22,29 +22,36 @@ ...@@ -22,29 +22,36 @@
<ProjectGuid>{18C1BF83-598C-42F3-B8AD-B770B3F405C0}</ProjectGuid> <ProjectGuid>{18C1BF83-598C-42F3-B8AD-B770B3F405C0}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>FreemudAPI</RootNamespace> <RootNamespace>FreemudAPI</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
......
...@@ -59,7 +59,7 @@ public : ...@@ -59,7 +59,7 @@ public :
std::stringstream sstr; std::stringstream sstr;
sstr << "FreemudAPI" << t->tm_year + 1900 << t->tm_mon + 1 << t->tm_mday; sstr << u8"FreemudAPI" << t->tm_year + 1900 << t->tm_mon + 1 << t->tm_mday;
std::string filename = std::string(sstr.str().c_str()); std::string filename = std::string(sstr.str().c_str());
......
...@@ -13,13 +13,13 @@ int _Recv(SOCKET socket, char *ptr, int length) ...@@ -13,13 +13,13 @@ int _Recv(SOCKET socket, char *ptr, int length)
LOG() << "Error: EINTR."; LOG() << "Error: EINTR.";
continue; continue;
} }
LOG() << "Error: other recv error."; LOG() << u8"Error: other recv error.";
return totalLen; return totalLen;
} else if( totalLen == 0) { } else if( totalLen == 0) {
LOG() << "Error: connect closed."; LOG() << u8"Error: connect closed.";
return 0; return 0;
} }
LOG() << "Total: Size: " << totalLen <<" Data: " << ptr; LOG() << u8"Total: Size: " << totalLen << u8" Data: " << ptr;
} while(0); } while(0);
return totalLen; return totalLen;
...@@ -68,7 +68,7 @@ int Recv(SOCKET socket, char *ptr, unsigned int byteSize) ...@@ -68,7 +68,7 @@ int Recv(SOCKET socket, char *ptr, unsigned int byteSize)
} }
if (byteSize < dataLen) { // 判断接收Buffer长度是否足够 if (byteSize < dataLen) { // 判断接收Buffer长度是否足够
LOG() << "Error. Buffer overflow, Except size: " << byteSize << " Actual size: " << dataLen; LOG() << u8"Error. Buffer overflow, Except size: " << byteSize << u8" Actual size: " << dataLen;
delete[] recvBuf; delete[] recvBuf;
delete[] tempBuf; delete[] tempBuf;
return FMError_BufferOverflow.Code(); return FMError_BufferOverflow.Code();
......
...@@ -20,7 +20,7 @@ int Send(SOCKET socket, const char *ptr) ...@@ -20,7 +20,7 @@ int Send(SOCKET socket, const char *ptr)
int tempLen = -1; int tempLen = -1;
if( (tempLen = send(socket, sendData, sendLength, 0)) < 0) { if( (tempLen = send(socket, sendData, sendLength, 0)) < 0) {
LOG() << "Error: other error."; LOG() << u8"Error: other error.";
} }
if(setting.needSocketHeaderSend) { if(setting.needSocketHeaderSend) {
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
...@@ -28,23 +28,27 @@ ...@@ -28,23 +28,27 @@
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment