Commit fffab4a7 by 李定达

1.天福dll

parents
fmdlltest/Release/
fmdlltest/Debug/
fmdll/Release/
fmdll/Debug/
*.sdf
fmdlltest/fmdlltest.vcxproj.user
*.vcxproj
*.filters
*.user

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fmdll", "fmdll\fmdll.vcxproj", "{3A8FED77-83D0-4167-8F64-D17090AD6111}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fmdlltest", "fmdlltest\fmdlltest.vcxproj", "{2080F357-1774-4F21-9C07-3CFFE4F9E74F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3A8FED77-83D0-4167-8F64-D17090AD6111}.Debug|Win32.ActiveCfg = Debug|Win32
{3A8FED77-83D0-4167-8F64-D17090AD6111}.Debug|Win32.Build.0 = Debug|Win32
{3A8FED77-83D0-4167-8F64-D17090AD6111}.Release|Win32.ActiveCfg = Release|Win32
{3A8FED77-83D0-4167-8F64-D17090AD6111}.Release|Win32.Build.0 = Release|Win32
{2080F357-1774-4F21-9C07-3CFFE4F9E74F}.Debug|Win32.ActiveCfg = Debug|Win32
{2080F357-1774-4F21-9C07-3CFFE4F9E74F}.Debug|Win32.Build.0 = Debug|Win32
{2080F357-1774-4F21-9C07-3CFFE4F9E74F}.Release|Win32.ActiveCfg = Release|Win32
{2080F357-1774-4F21-9C07-3CFFE4F9E74F}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
File added
LIBRARY
EXPORTS
initFmDll
fmSendAndWaitRecJsonData
endFmDll
\ No newline at end of file
#ifndef FMNETWORK_H
#define FMNETWORK_H
/*************************************************
*功能:初始化dll(调用一次)
*返回:-1 失败;0 成功;
**************************************************/
int _stdcall initFmDll();
/*************************************************
*
*功能:发送和接收数据(调用该方法会阻塞直到接收到数据或超时[内部超时时间为60秒,从该方法被调用时计算])
*
*参数:_inJson输入参数(传入参数必须为合法的json字符串,且长度小于8192,传入参数汉字编码需韦UTF-8)
* _outJson输出参数(空的字符数组,数组长度需大于4096)
*
*返回:0 成功;
* 101 socket连接fmclient.exe失败
* 102 发送的数据不合法或发送数据到fmclient.exe失败
* 103 接收fmclient.exe数据失败
**************************************************/
int _stdcall fmSendAndWaitRecJsonData(const char * _inJson, char * _outJson);
/*************************************************
*
*功能:清理dll(卸载fmsocket.dll调用一次)
**************************************************/
void _stdcall endFmDll();
#endif
\ No newline at end of file
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <direct.h>
#include <io.h>
#include <time.h>
#include <windows.h>
#include <winsock.h>
#include <DbgHelp.h>
#include "..\fmdll\fmnetwork.h"
#define MAX_BUF_SIZE 4096
#pragma comment(lib, "..\\Debug\\fmdll.lib")
void GetProcPath(char * pathBuf)
{
int curPos;
GetModuleFileName(NULL, pathBuf, MAX_PATH);
curPos = strlen(pathBuf) - 1;
while('\\' != pathBuf[curPos])
{
curPos--;
}
curPos++;
pathBuf[curPos] = '\0';
}
int main()
{
FILE *fp = NULL;
char in[MAX_BUF_SIZE] = {0};
char out[MAX_BUF_SIZE] = {0};
fp = fopen("F:\\VM\\fm\\fmdlllog\\ld.log", "r");
fscanf(fp, "%s", in);
printf("1: %s\r\n", in );
if(0 != initFmDll())
{
printf("sendData2Client failed !\n");
return 0;
}
if(0 != fmSendAndWaitRecJsonData(in, out))
{
printf("fmSendAndWaitRecJsonData failed !\n");
}
printf("recive data : %s \n", out);
Sleep(2*1000);
endFmDll();
return 0;
}
//int main()
//{
// char _inJson[MAX_BUF_SIZE] = "{\"ver\":2,\"business_date\":\"20170928\",\"transactions\":[{\"vdata\":\"2017-09-29\",\"code\":\"992441740\",\"pay_amount\":3250,\"products\":[{\"pid\":\"0802761\",\"sales_type\":\"Normal\",\"consume_num\":\"1\",\"name\":\"L焗烤三文治#\",\"price\":\"000000000650\",\"pcata\":\"081312\"},{\"pid\":\"1300985\",\"sales_type\":\"Normal\",\"consume_num\":\"1\",\"name\":\"农夫山庄经典九制妙酸奶梅\",\"price\":\"000000000600\",\"pcata\":\"130401\"},{\"pid\":\"0201681\",\"sales_type\":\"Normal\",\"consume_num\":\"1\",\"name\":\"D吉香居麻辣大头菜\",\"price\":\"000000000300\",\"pcata\":\"020801\"},{\"pid\":\"1301832\",\"sales_type\":\"Normal\",\"consume_num\":\"1\",\"name\":\"洽洽焦糖味瓜子\",\"price\":\"000000000700\",\"pcata\":\"130201\"},{\"pid\":\"0700746\",\"sales_type\":\"Normal\",\"consume_num\":\"1\",\"name\":\"农夫水溶C100西柚#\",\"price\":\"000000000500\",\"pcata\":\"070403\"},{\"pid\":\"0802764\",\"sales_type\":\"Normal\",\"consume_num\":\"2\",\"name\":\"L榴莲酥#\",\"price\":\"000000000250\",\"pcata\":\"081312\"}],\"ebcode\":\"0000000256\"}],\"reqtype\":71,\"store_id\":\"2612\",\"operator_id\":\"01\",\"station_id\":\"2612\",\"trans_id\":\"2017092826121187\"}";
// //char _inJson[MAX_BUF_SIZE] ="{\"ver\":2, \"operator_id\": \"00000002\", \"reqtype\": 72,\"station_id\": 1,\"store_id\": \"999999\",\"trans_id\": 110,\"business_date\":\"20150701\",\"transactions\": [{\"amount\": 0.01,\"undis_amount\":0,\"code\": \"28\"}]}";
// //char _inJson[MAX_BUF_SIZE] = "{\"ver\":2,\"operator_id\": \"00000002\", \"reqtype\": 72,\"station_id\": 1,\"store_id\": \"999999\",\"trans_id\": 110,\"business_date\":\"20150701\",\"transactions\": [{\"amount\: 1974,\"undis_amount\":0,\"code\": \"289631206996295092\",\"products\: [{\"consume_num\": 1,\"sales_type\": \"FREE\",\"price\": 1000,\"pid\": \"0079020\", \"seq\": 1 },{ \"consume_num\": 1,\"sales_type\": \"NORMAL\",\"price\": 1974,\"pid\": \"0077842\",\"seq\": 2}]}]}";
// //char _inJson[MAX_BUF_SIZE] = "{\"ver\":1,\"reqtype\": 0,\"coupon\": \"122222222222\",\"station_id\": \"1\",\"store_id\": \"999999\",\"operator_id\": \"00000002\" }";
// //char _inJson[MAX_BUF_SIZE] = "{\"business_date\":\"20170216\",\"clientReqCount\":1,\"operator_id\":\"00000002\",\"reqtype\":72,\"station_id\":1,\"store_id\":\"99999\",\"trans_id\":1,\"transactions\":[{\"amount\":1,\"code\":\"130172197545004263\"}],\"ver\":1}";
// char _outJson[MAX_BUF_SIZE] = {0};
// char path[MAX_PATH] = {0};
// int i = 0;
//
//
//
// GetProcPath(path);
// printf("%s", path);
//
// if(0 != initFmDll())
// {
// printf("sendData2Client failed !\n");
// goto MainExit;
// }
//
// do
// {
// if(0 != fmSendAndWaitRecJsonData(_inJson, _outJson))
// {
// printf("fmSendAndWaitRecJsonData failed !\n");
// }
// printf("recive data : %s \n", _outJson);
// Sleep(2*1000);
// i ++;
// }while(i < 2);
// endFmDll();
//MainExit:
// system("pause");
// return 0;
//}
//#include <stdio.h>
//#include <stdlib.h>
//#include <Windows.h>
//
//typedef int ( *Init ) ();
//typedef void ( *Destory ) ();
//typedef int ( *SendAndReceiveData ) (const char *, char *);
//
//int main(int argc, char **argv)
//{
//
// HINSTANCE _socket_hd;
// Init _init;
// Destory _destory;
// SendAndReceiveData _sendandreceivedata;
//
// char _senddata [8000] = "{\"coupon\":\"123456789\",\"operator_id\":\"02\",\"reqtype\":0,\"station_id\":1,\"store_id\":\"2\",\"ver\":2}";
// char _receivedata[8000] = {0};
//
// /***********************************************************************
// *加载FMSocket.dll
// ************************************************************************/
// _socket_hd = LoadLibraryA( "FMSocket.dll" );
// if(_socket_hd == NULL )
// {
// printf( "load FMSocket.dll failed \n" );
// return -1;
// }
//
// /***********************************************************************
// *获取FMSocket.dll数据发送初始化方法
// ************************************************************************/
// _init = ( Init )GetProcAddress( _socket_hd, "Init" );
// if(_init == NULL)
// {
// printf( "get function init failed \n" );
// return -1;
// }
//
// /***********************************************************************
// *获取FMSocket.dll数据发送销毁方法
// ************************************************************************/
// _destory = ( Destory )GetProcAddress( _socket_hd, "Destory" );
// if( _destory == NULL )
// {
// printf( "get function Destroy failed \n" );
// return -1;
// }
//
// /***********************************************************************
// *获取FMSocket.dll数据接收和发送方法
// ************************************************************************/
// _sendandreceivedata = ( SendAndReceiveData )GetProcAddress( _socket_hd,"SendAndReceiveData" );
// if( _sendandreceivedata == NULL )
// {
// printf( "get function SendAndReceiveData failed \n" );
// return -1;
// }
//
// /***********************************************************************
// *初始化
// ************************************************************************/
// if( _init() == -1 )
// {
// printf( "init FMSocket.dll failed \n" );
// return -1;
// }
// /***********************************************************************
// *发送和接收数据
// ************************************************************************/
// if( _sendandreceivedata(_senddata, _receivedata) == 0 )
// {
// printf( "receive data from fmclient : %s \n", _receivedata );
// }else
// {
// printf( "receive data from fmclient failed \n" );
// }
// /***********************************************************************
// *清理
// ************************************************************************/
// _destory();
//
// FreeLibrary(_socket_hd);
//
// system( "pause" );
//
// return 0;
//}
\ 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