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
//Log("Initialising Winsock...");
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)
{
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());
......@@ -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)
{
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) < 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) {
LOG() << "Send data: " << req;
LOG() << u8"Send data: " << req;
}
int recv_size = SOCKET_ERROR;
......@@ -66,19 +66,19 @@ extern "C" __declspec(dllexport) int __stdcall FMGetResponse(const char* req, ch
memset(rsp, 0, byteSize);
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()) {
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()) {
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()) {
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) {
LOG() << "Recv size: " << recv_size << " Recv data: " << rsp;
} 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);
}
......
<?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">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
......@@ -22,29 +22,36 @@
<ProjectGuid>{18C1BF83-598C-42F3-B8AD-B770B3F405C0}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>FreemudAPI</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
......
......@@ -59,7 +59,7 @@ public :
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());
......
......@@ -13,13 +13,13 @@ int _Recv(SOCKET socket, char *ptr, int length)
LOG() << "Error: EINTR.";
continue;
}
LOG() << "Error: other recv error.";
LOG() << u8"Error: other recv error.";
return totalLen;
} else if( totalLen == 0) {
LOG() << "Error: connect closed.";
LOG() << u8"Error: connect closed.";
return 0;
}
LOG() << "Total: Size: " << totalLen <<" Data: " << ptr;
LOG() << u8"Total: Size: " << totalLen << u8" Data: " << ptr;
} while(0);
return totalLen;
......@@ -68,7 +68,7 @@ int Recv(SOCKET socket, char *ptr, unsigned int byteSize)
}
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[] tempBuf;
return FMError_BufferOverflow.Code();
......
......@@ -20,7 +20,7 @@ int Send(SOCKET socket, const char *ptr)
int tempLen = -1;
if( (tempLen = send(socket, sendData, sendLength, 0)) < 0) {
LOG() << "Error: other error.";
LOG() << u8"Error: other error.";
}
if(setting.needSocketHeaderSend) {
......
<?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">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
......@@ -28,23 +28,27 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<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