Commit eeafa578 by NitefullWind

1. 重新实现send和recv方法。 2. 添加测试项目。

parent 3176f1c8
......@@ -4,4 +4,5 @@ ipch/
*.sdf
*.suo
*.user
*.filters
\ No newline at end of file
*.filters
*.db
\ No newline at end of file
......@@ -3,16 +3,34 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FreemudAPI", "FreemudAPI\FreemudAPI.vcxproj", "{18C1BF83-598C-42F3-B8AD-B770B3F405C0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test\test.vcxproj", "{8AC9394E-ADF6-4B15-9D8D-FB2D256C596B}"
ProjectSection(ProjectDependencies) = postProject
{18C1BF83-598C-42F3-B8AD-B770B3F405C0} = {18C1BF83-598C-42F3-B8AD-B770B3F405C0}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{18C1BF83-598C-42F3-B8AD-B770B3F405C0}.Debug|Win32.ActiveCfg = Debug|Win32
{18C1BF83-598C-42F3-B8AD-B770B3F405C0}.Debug|Win32.Build.0 = Debug|Win32
{18C1BF83-598C-42F3-B8AD-B770B3F405C0}.Debug|x64.ActiveCfg = Debug|x64
{18C1BF83-598C-42F3-B8AD-B770B3F405C0}.Debug|x64.Build.0 = Debug|x64
{18C1BF83-598C-42F3-B8AD-B770B3F405C0}.Release|Win32.ActiveCfg = Release|Win32
{18C1BF83-598C-42F3-B8AD-B770B3F405C0}.Release|Win32.Build.0 = Release|Win32
{18C1BF83-598C-42F3-B8AD-B770B3F405C0}.Release|x64.ActiveCfg = Release|x64
{18C1BF83-598C-42F3-B8AD-B770B3F405C0}.Release|x64.Build.0 = Release|x64
{8AC9394E-ADF6-4B15-9D8D-FB2D256C596B}.Debug|Win32.ActiveCfg = Debug|Win32
{8AC9394E-ADF6-4B15-9D8D-FB2D256C596B}.Debug|Win32.Build.0 = Debug|Win32
{8AC9394E-ADF6-4B15-9D8D-FB2D256C596B}.Debug|x64.ActiveCfg = Debug|x64
{8AC9394E-ADF6-4B15-9D8D-FB2D256C596B}.Debug|x64.Build.0 = Debug|x64
{8AC9394E-ADF6-4B15-9D8D-FB2D256C596B}.Release|Win32.ActiveCfg = Release|Win32
{8AC9394E-ADF6-4B15-9D8D-FB2D256C596B}.Release|Win32.Build.0 = Release|Win32
{8AC9394E-ADF6-4B15-9D8D-FB2D256C596B}.Release|x64.ActiveCfg = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -3,10 +3,9 @@
#include "stdafx.h"
#include <stdio.h>
#include <errno.h>
#include <winsock2.h>
#include <Windows.h>
#include "fmerror.h"
#include "send.h"
#include "recv.h"
#pragma comment(lib, "ws2_32.lib")
......@@ -17,57 +16,15 @@
#define FM_ERROR -1;
#define MAXLINE 4096
#define FM_ERROR_SOCKET "{\"statusCode\": 104, \"msg\": \"本地Socket通讯错误.\"}"
#define FM_ERROR_TIMEOUT "{\"statusCode\": 104, \"msg\": \"本地Socket通讯超时.\"}"
#define Log(_Format, ...) {printf("Function:%s, Line:%d: ", __FUNCTION__, __LINE__); printf(_Format, __VA_ARGS__); printf("\n");}
static int read_cnt;
static char *read_ptr;
static char read_buf[MAXLINE];
static int my_read(int fd, char *ptr)
{
if (read_cnt <= 0) {
again:
if ((read_cnt = recv(fd, read_buf, sizeof(read_buf), 0)) < 0) {
if (errno == EINTR)
goto again;
return (-1);
}
else if (read_cnt == 0)
return (0);
read_ptr = read_buf;
}
read_cnt--;
*ptr = *read_ptr++;
return(1);
}
int readline(int fd, void *vptr, size_t maxlen)
{
int n, rc;
char c, *ptr;
ptr = (char*)vptr;
for (n = 1; n<maxlen; n++) {
if ((rc = my_read(fd, &c)) == 1) {
*ptr++ = c;
if (c == '\n')
break; /* newline is stored, like fgets() */
}
else if (rc == 0) {
*ptr = 0;
return(n - 1); /* EOF, n-1 */
}
else {
return (-1); /* error, errno set by read() */
}
}
*ptr = 0; /* null terminatr like fgets() */
return (n);
}
#define MakeError(msg, ...) \
strset(ErrorMsg, 0); \
sprintf(ErrorMsg, msg, __VA_ARGS__); \
_error = Freemud::Error(FM_ERROR_CODE_SOCKET, ErrorMsg); \
Log(ErrorMsg); \
isOk = false;
extern "C" {
__declspec(dllexport) int __stdcall FMGetResponse(const char* req, char* rsp)
......@@ -77,57 +34,56 @@ extern "C" {
struct sockaddr_in _server;
bool isOk = true;
Freemud::Error _error;
char ErrorMsg[1000] = {0};
Log("Initialising Winsock...");
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
{
Log("Error. Startup error: %d", WSAGetLastError());
isOk = false;
MakeError("Error. Startup error: %d", WSAGetLastError())
}
if(isOk && (_socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
Log("Could not create socket: %d", WSAGetLastError());
isOk = false;
MakeError("Could not create socket: %d", WSAGetLastError())
}
_server.sin_addr.S_un.S_addr = (ULONG)inet_addr(SERVERIP);
_server.sin_family = AF_INET;
_server.sin_port = htons(SERVERPORT);
// 设置超时时间
const int sendTimeOut = 1 * 60 * 1000;
const int recvTimeOut = 5 * 60 * 1000;
setsockopt(_socket, SOL_SOCKET, SO_SNDTIMEO, (char*)&sendTimeOut, sizeof(int));
setsockopt(_socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&recvTimeOut, sizeof(int));
if (isOk && connect(_socket, (struct sockaddr *)&_server, sizeof(_server)) < 0)
{
Log("Error. connect error: %d", WSAGetLastError());
isOk = false;
MakeError("Error. connect error: %d", WSAGetLastError())
}
if (isOk && send(_socket, req, strlen(req), 0) < 0)
//if (isOk && send(_socket, req, strlen(req), 0) < 0)
if (isOk && Send(_socket, req) < 0)
{
Log("Error. Send error: %d", WSAGetLastError());
isOk = false;
MakeError("Error. Send error: %d", WSAGetLastError())
}
if (isOk) {
Log("Send data: %s", req);
}
int recv_size = SOCKET_ERROR;
if (isOk && (recv_size = recv(_socket, rsp, 40960, 0)) == SOCKET_ERROR)
//if (isOk && (recv_size = recv(_socket, rsp, 40960, 0)) == SOCKET_ERROR)
//if (isOk && (recv_size = readline(_socket, rsp, 40960)) == SOCKET_ERROR)
//if (isOk && (recv_size = my_read(_socket, rsp)) == SOCKET_ERROR)
if (isOk && (recv_size = Recv(_socket, rsp)) == SOCKET_ERROR)
{
Log("Error. Recv error: %d", WSAGetLastError());
isOk = false;
MakeError("Error. Recv error: %d", WSAGetLastError())
} else if(recv_size == 0) {
MakeError("Error. Connect closed: %d", WSAGetLastError())
}
if (isOk) {
Log("Recv size: %d, Recv data: %s", recv_size, rsp);
} else if (WSAGetLastError() == 10060) {
strcpy(rsp, FM_ERROR_TIMEOUT);
} else if (_error.Code() == FM_ERROR_CODE_SOCKET) {
sprintf(ErrorMsg, "{\"statusCode\": 104, \"msg\": \"本地Socket通讯错误(%s).\"}", _error.Msg().c_str());
strcpy(rsp, ErrorMsg);
}
closesocket(_socket);
......
......@@ -5,10 +5,18 @@
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{18C1BF83-598C-42F3-B8AD-B770B3F405C0}</ProjectGuid>
......@@ -21,28 +29,53 @@
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<TargetName>$(ProjectName)_x64</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetName>$(ProjectName)_x64</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
......@@ -56,6 +89,19 @@
<ModuleDefinitionFile>FreemudAPI.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;FREEMUDAPI_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>FreemudAPI.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
......@@ -73,28 +119,58 @@
<ModuleDefinitionFile>FreemudAPI.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;FREEMUDAPI_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ModuleDefinitionFile>FreemudAPI.def</ModuleDefinitionFile>
<Profile>false</Profile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="FreemudAPI.def" />
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="fmerror.h" />
<ClInclude Include="recv.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="send.h" />
<ClInclude Include="socketHeader.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged>
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</CompileAsManaged>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
</PrecompiledHeader>
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</CompileAsManaged>
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</CompileAsManaged>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="FreemudAPI.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
......
......@@ -15,5 +15,4 @@ BOOL APIENTRY DllMain( HMODULE hModule,
break;
}
return TRUE;
}
}
\ No newline at end of file
#include <string>
namespace Freemud
{
class Error
{
public:
Error():
_code(0),
_msg(std::string())
{
}
Error(int code, const char *msg):
_code(code),
_msg(std::string(msg))
{
}
Error(int code, std::string msg):
_code(code),
_msg(msg)
{
}
Error(const Error &orig):
_code(orig.Code()),
_msg(orig.Msg())
{
}
Error& operator = (const Error &rhs)
{
this->_code = rhs.Code();
this->_msg = rhs.Msg();
return *this;
}
bool operator == (const Error &rhs)
{
if(this->_code == rhs.Code() && this->_msg == rhs.Msg()) {
return true;
}
return false;
}
void setCode(int code){
this->_code = code;
}
int Code() const{
return this->_code;
}
void setMsg(const char *msg) {
this->_msg = std::string(msg);
}
void setMsg(std::string msg) {
this->_msg = msg;
}
std::string Msg() const {
return this->_msg;
}
private:
int _code;
std::string _msg;
};
}
\ No newline at end of file
#include "stdafx.h"
int Recv(SOCKET socket, char *ptr)
{
int tempLen = -1, totalLen = 0, needLen = -1;
char tempBuf[MAX_SIZE+1] = {0};
#ifdef NeedSocketHeaderRecv
#else
while(totalLen ==0 || totalLen < needLen) {
strset(tempBuf, 0);
if( (tempLen = recv(socket, tempBuf, MAX_SIZE, 0)) < 0) {
if (tempLen == EINTR) {
Log("Error: EINTR.\n");
continue;
}
Log("Error: other recv error.\n");
return tempLen;
} else if( tempLen == 0) {
Log("Error: connect closed.\n");
return 0;
} else {
strcpy(ptr+totalLen, tempBuf);
totalLen += tempLen;
Log("Temp: Size:%d, Data:%s\n", tempLen, tempBuf);
Log("Total: Size:%d, Data:%s\n", totalLen, ptr);
}
}
#endif
return totalLen;
}
static int read_cnt;
static char *read_ptr;
static char read_buf[MAX_SIZE];
const int FM_ERROR_CODE_SOCKET = -1;
static int my_read(int fd, char *ptr)
{
if (read_cnt <= 0) {
again:
if ((read_cnt = recv(fd, read_buf, sizeof(read_buf), 0)) < 0) {
if (errno == EINTR)
goto again;
return (-1);
}
else if (read_cnt == 0)
return (0);
read_ptr = read_buf;
}
read_cnt--;
*ptr = *read_ptr++;
return(1);
}
int readline(int fd, void *vptr, size_t maxlen)
{
int n, rc;
char c, *ptr;
ptr = (char*)vptr;
for (n = 1; n<maxlen; n++) {
if ((rc = my_read(fd, &c)) == 1) {
*ptr++ = c;
if (c == '\n')
break; /* newline is stored, like fgets() */
}
else if (rc == 0) {
*ptr = 0;
return(n - 1); /* EOF, n-1 */
}
else {
return (-1); /* error, errno set by read() */
}
}
*ptr = 0; /* null terminatr like fgets() */
return (n);
}
#include "stdafx.h"
#include "socketHeader.h"
int Send(SOCKET socket, const char *ptr)
{
char *sendData = (char*)ptr;
#ifdef NeedSocketHeaderSend
int addHeaderDataLength = GetAddHeaderReqDataLength(ptr);
char *addHeaderData = new char[addHeaderDataLength];
GetAddHeaderReqData(ptr, addHeaderData, addHeaderDataLength);
sendData = (char*)addHeaderData;
#endif
int tempLen = -1, totalLen = 0;
if( (tempLen = send(socket, sendData, strlen(sendData), 0)) < 0) {
Log("Error: other error.\n");
return tempLen;
} else {
// Log("Total: Size:%d, Data:%s\n", tempLen, ptr);
return tempLen;
}
}
\ No newline at end of file
#include "stdafx.h"
typedef struct {
unsigned int flag; // 固定值 0x4d46
unsigned int ver; // 固定值 0x2
unsigned int len; // 原始请求数据的数据长度
}FMSOCKHEADER;
unsigned int GetAddHeaderReqDataLength(const char *originData)
{
int originLen = strlen(originData); //获得原始数据长度
return originLen + sizeof(FMSOCKHEADER);
}
int GetAddHeaderReqData(const char *originData, char *addHeaderReqData, unsigned int addHeaderReqDataLength)
{
int originLen = strlen(originData); //获得原始数据长度
int newReqDataLength = originLen + sizeof(FMSOCKHEADER);
if (addHeaderReqDataLength < newReqDataLength) {
return 0;
}
// 设置消息头的值
FMSOCKHEADER header = {0, 0, 0};
header.flag = 0x4d46;
header.len = originLen;
header.ver = 0x2;
// 在原始数据前加消息头
strset(addHeaderReqData, 0);
memset(addHeaderReqData, 0, originLen + sizeof(FMSOCKHEADER));
memcpy(addHeaderReqData, &header, sizeof(FMSOCKHEADER)); // 将消息头拷贝至addHeaderReqData
strcat(addHeaderReqData, originData); //将原始数据追加到addHeaderReqData
return newReqDataLength;
}
\ No newline at end of file
......@@ -12,5 +12,23 @@
#include <windows.h>
// TODO: 在此处引用程序需要的其他头文件
#include <stdio.h>
#include <errno.h>
#include <winsock2.h>
#include <Windows.h>
#define Log(_Format, ...) {printf("Function:%s, Line:%d: ", __FUNCTION__, __LINE__); printf(_Format, __VA_ARGS__); printf("\n");}
const int MAX_SIZE = 40960;
// 设置超时时间
const int sendTimeOut = 0.5 * 60 * 1000;
const int recvTimeOut = 0.5 * 60 * 1000;
#ifndef NeedSocketHeaderSend
//#define NeedSocketHeaderSend
#endif
#ifndef NeedSocketHeaderRecv
//#define NeedSocketHeaderRecv
#endif
\ No newline at end of file
========================================================================
控制台应用程序:test 项目概述
========================================================================
应用程序向导已为您创建了此 test 应用程序。
本文件概要介绍组成 test 应用程序的每个文件的内容。
test.vcxproj
这是使用应用程序向导生成的 VC++ 项目的主项目文件,
其中包含生成该文件的 Visual C++
的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。
test.vcxproj.filters
这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。
它包含有关项目文件与筛选器之间的关联信息。 在 IDE
中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。
例如,“.cpp”文件与“源文件”筛选器关联。
test.cpp
这是主应用程序源文件。
/////////////////////////////////////////////////////////////////////////////
其他标准文件:
StdAfx.h,StdAfx.cpp
这些文件用于生成名为 test.pch 的预编译头 (PCH) 文件和
名为 StdAfx.obj 的预编译类型文件。
/////////////////////////////////////////////////////////////////////////////
其他注释:
应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。
/////////////////////////////////////////////////////////////////////////////
// stdafx.cpp : 只包括标准包含文件的源文件
// test.pch 将作为预编译头
// stdafx.obj 将包含预编译类型信息
#include "stdafx.h"
// TODO: 在 STDAFX.H 中
// 引用任何所需的附加头文件,而不是在此文件中引用
// stdafx.h : 标准系统包含文件的包含文件,
// 或是经常使用但不常更改的
// 特定于项目的包含文件
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: 在此处引用程序需要的其他头文件
#include <Windows.h>
\ No newline at end of file
#pragma once
// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
// 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将
// WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
#include <SDKDDKVer.h>
// test.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
EXTERN_C typedef int (__stdcall *FMGetResponse)(const char* req, char* rsp);
int _tmain(int argc, _TCHAR* argv[])
{
HMODULE hdll = LoadLibraryA("FreemudAPI.dll");
if(hdll == NULL) {
printf("Load dll failed!");
exit(0);
}
FMGetResponse fmFunc = FMGetResponse(GetProcAddress(hdll, "FMGetResponse"));
if(fmFunc == NULL) {
printf("Load function failed!");
exit(0);
}
//char req[] = {"I'm test request data."};
char req[] = {"{\"fm_cmd\": 10031}"};
//char bigReq[4096] = {0};
//for(int i=0; i<4096; i++) {
// bigReq[i] = 'a';
//}
char rsp[40960] = {0};
int ret = fmFunc(req, rsp);
printf("================================================\n"
"Code: %d\n"
"Data: %s\n", ret, rsp);
system("pause");
return 0;
}
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8AC9394E-ADF6-4B15-9D8D-FB2D256C596B}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>test</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<TargetName>$(ProjectName)_x64</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<ExecutablePath>E:\Code\FreemudAPI\x64\Release;$(ExecutablePath)</ExecutablePath>
<TargetName>$(ProjectName)_x64</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<ExecutablePath>E:\Code\FreemudAPI\x64\Release;$(ExecutablePath)</ExecutablePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="test.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
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