【阳光飞狐__与财富同行】

标题: 飞狐交易师 (foxtrader) 连结 DLL 的方法 ----- (续) [打印本页]

作者: ycng    时间: 2019-8-11 16:12
标题: 飞狐交易师 (foxtrader) 连结 DLL 的方法 ----- (续)
//////////////////////////////////////////////////////////foxfunc.cpp

//FoxFunc.cpp : Defines the entry point for the DLL application.
//
#include<string.h>
#include<stdio.h>
#include<io.h>
#include<math.h>
#include<iostream>
#include"stdafx.h"
#include"FoxFunc.h"
usingnamespace std;
BOOLAPIENTRY DllMain( HANDLE hModule,
DWORDul_reason_for_call,
LPVOIDlpReserved
)
{
switch(ul_reason_for_call)
{
caseDLL_PROCESS_ATTACH:
caseDLL_THREAD_ATTACH:
caseDLL_THREAD_DETACH:
caseDLL_PROCESS_DETACH:
break;
}
returnTRUE;
}
//计算收盘价的均价,一个常数参数,表示计算周期
//调用方法:
//"FOXFUNC@MYMACLOSE"(5)
/*
//extern "C" double __cdecl ppow10(double ctemp,doublelength); - - - > wrong, extern "C" is to declare pow10coming from a .dll or .lib
//extern "C" double ppow10(double ctemp,double length); - - -> both are the same
*/
extern"C" double __cdecl ppow10(double ,double );
//double ppow10(double ,double );
//call pow10() by __cdecl
//!!!!!!!! use "C" for Microsoft visual C++ compiler
//!!!!!!!! use "C" for Microsoft visual C++ compiler
//!!!!!!!! use "C" for Microsoft visual C++ compiler
//!!!!!!!! use "C" for Microsoft visual C++ compiler
//!!!!!!!! use "C" for Microsoft visual C++ compiler
__declspec(dllexport)int WINAPI MYMACLOSE(CALCINFO* pData)
{
if( // pData->m_pfParam1 && //参数1有效
//pData->m_nParam1Start<0 && //参数1为常数
//pData->m_pfParam2==NULL ) //仅有一个参数
//pData->m_pfParam1 && pData->m_pfParam2 &&pData->m_pfParam3 && pData->m_pfParam4
//&& pData->m_pfParam5 && pData->m_pfParam6 &&pData->m_nParam1Start>=0 &&
//pData->m_pfParam7==NULL)
//pData->m_pfParam1 && pData->m_pfParam2 &&pData->m_pfParam3 && pData->m_nParam1Start>=0 &&
pData->m_pCalcParam[0].m_nParamStart>=0&& pData->m_pCalcParam[1].m_nParamStart>=0
&&pData->m_pCalcParam[2].m_nParamStart>=0)
{
floatfParam = *pData->m_pfParam4; //pointer ,pData->m_pCalcParam[3].m_nParamStart >= 0
intnPeriod = (int)fParam; //参数1
//const float* cpParam = pData->m_pfParam2; // cpParam = pointer to
constfloat* cpParam2 =pData->m_pCalcParam[1].m_pfParam; // cpParam =pointer to
constfloat* cpParam3 =pData->m_pCalcParam[2].m_pfParam; // cpParam =pointer to
constfloat* cpParam4 =pData->m_pCalcParam[3].m_pfParam; // cpParam =pointer to
//const float* cpParam5 =pData->m_pCalcParam[4].m_pfParam; //cpParam = pointer to
//in foxtraderoooq:"MYFUNC2010@MYMACLOSE"(c,c,c,6),colorffffff,linethick5;// cpParam5 =pData->m_pCalcParam[4].m_pfParam
//pData->m_pCalcParam[5].m_fParam); //value
//const float* pValue1 = pData->m_pCalcParam[0].m_pfParam;
//const float* pValue2 = pData->m_pCalcParam[1].m_pfParam;
//const float* pValue3 = pData->m_pCalcParam[2].m_pfParam;
//const float* pValue4 = pData->m_pCalcParam[3].m_pfParam;
//const float* pValue5 = pData->m_pCalcParam[4].m_pfParam;
if(nPeriod>0)
{
floatfTotal;
inti, j;
intndata = pData->m_nNumData;
//float yy[5000][1];
for( i = nPeriod-1; i < pData->m_nNumData; i++)//计算nPeriod周期的均线,数据从nPeriod-1开始有效
{
fTotal= 0.0f;
doublelngth=5.0;
doublectemp=4.0;
//float yy1[5000][1];
for( j = 0; j < nPeriod; j++ ) //累加
{
fTotal= pData->m_pData.m_fClose; // @@@@@@@ vc++ 2010 cl.exe 使pData->m_pData[i-j].m_fClose错误
}
//pData->m_pResultBuf = fTotal*1.03; //平均
fTotal= cpParam3;
pData->m_pResultBuf= fTotal*1.03; //平均
//ctemp = (double) pData->m_pResultBuf; // double & - - - >overload a float value , double * - - - > overload a pointer todouble
//pData->m_pResultBuf= (float) ppow10(ctemp,lngth); // float &- - - > overload a float value
pData->m_pResultBuf=(float) ppow10( (double) pData->m_pResultBuf,lngth); // float &- - - > overload a float value, (float) = overload
}
returnnPeriod-1;
}
}
return-1;
}
//计算均价,2个参数,参数1为待求均线的数据,参数2表示计算周期
//调用方法:
//"FOXFUNC@MYMAVAR"(CLOSE-OPEN,5)
__declspec(dllexport)int WINAPI MYMAVAR(CALCINFO* pData)
{
if(pData->m_pfParam1&& pData->m_pfParam2 && //参数1,2有效
pData->m_nParam1Start>=0&& //参数1为序列数
pData->m_pfParam3==NULL)//2个参数
{
constfloat* pValue = pData->m_pfParam1; //参数1
intnFirst = pData->m_nParam1Start; //有效值起始位
floatfParam = *pData->m_pfParam2; //参数2
intnPeriod = (int)fParam;
if(nFirst >= 0 && nPeriod > 0 )
{
floatfTotal;
inti, j;
for( i = nFirst+nPeriod-1; i < pData->m_nNumData; i++ )
{
fTotal= 0.0f;
for( j=0; j < nPeriod; j++ ) //累加
fTotal+= pValue[i-j];
pData->m_pResultBuf= fTotal/nPeriod;//平均
}
returnnFirst+nPeriod-1;
}
}
return-1;
}
//计算多个序列的均值,5个参数,参数1-4为待求多个序列,参数5用于举例说明数值参数的用法,实际在此例中无需该参数
/*
调用方法:
MA1:=MA(CLOSE,3);
MA2:=MA(CLOSE,6);
MA3:=MA(CLOSE,12);
MA4:=MA(CLOSE,24);
MYBBI:"FOXFUNC@MYBBI"(MA1, MA2, MA3, MA4, 4);
*/
__declspec(dllexport)int WINAPI MYBBI(CALCINFO* pData)
{
if( pData->m_pCalcParam[0].m_nParamStart >= 0 &&
pData->m_pCalcParam[1].m_nParamStart>= 0 &&
pData->m_pCalcParam[2].m_nParamStart>= 0 &&
pData->m_pCalcParam[3].m_nParamStart>= 0 ) //4个序列都含有效数值
{
//计算返回的序列的第一个有效值位置
intnFirst = pData->m_pCalcParam[2].m_nParamStart;//已知返回的序列的第一个有效值位置与第4个序列一致
//若不知,则
/*
intnFirst = pData->m_pCalcParam[0].m_nParamStart;
if( nFirst < pData->m_pCalcParam[1].m_nParamStart )
nFirst= pData->m_pCalcParam[1].m_nParamStart;
if( nFirst < pData->m_pCalcParam[2].m_nParamStart )
nFirst= pData->m_pCalcParam[2].m_nParamStart;
if( nFirst < pData->m_pCalcParam[3].m_nParamStart )
nFirst= pData->m_pCalcParam[3].m_nParamStart;
*/
constfloat* pValue1 = pData->m_pCalcParam[0].m_pfParam;
constfloat* pValue2 = pData->m_pCalcParam[1].m_pfParam;
constfloat* pValue3 = pData->m_pCalcParam[2].m_pfParam;
constfloat* pValue4 = pData->m_pCalcParam[3].m_pfParam;
constfloat* pValue5 = pData->m_pCalcParam[4].m_pfParam;
constfloat* pValue6 = pData->m_pCalcParam[5].m_pfParam;
//const float* pValue1 = pData->m_pfParam1;
//const float* pValue2 = pData->m_pfParam2;
//const float* pValue3 = pData->m_pfParam3;
//int nNum = (int)(*pData->m_pfParam4);//实际上该例中已知nNum=4,在此用于说明数值参数的用法
intnNum = (int)(pData->m_pCalcParam[6].m_fParam);//实际上该例中已知nNum=4,在此用于说明数值参数的用法
for(int i = nFirst; i < pData->m_nNumData; i++ )
{
pData->m_pResultBuf=
//(pValue1 + pValue2 + pValue3 )/nNum;
(pValue1+ pValue2 + pValue3 + pValue4+pValue5 + pValue6)/nNum;
}
returnnFirst;
}
return-1;
}



//////////////////////////////////////////////////////////////pow10.asm
;*******************************************************
;* *
;* Delphi Run Library *
;* *
;* Copyright (c) 1996,98 Inprise Corporation *
;*--------------------------------------------------------------------------
;* To compile "tasm32 /ml pow10.asm" *
;*--------------------------------------------------------------------------
;*******************************************************
.386
;.MODEL flat,c (error must be in segement block must have segment
;!!!!!11 important if ',c' is not used , must use 'public _ppow10, and'_ppow10 proc'
;!!!!!11 important if .MODEL flat,c is not used , must use ;_TEXTSEGMENT WORD PUBLIC
;'CODE'..._TEXT ENDS and must use 'public _ppow10 and '_ppow10 proc'
.MODELflat,c ; just use .code, no need for segment,!!!!!11 important if',c' is used , must use 'public ppow10, and 'ppow10 proc'
;ppow10 PROTO,aVal:PTR REAL8, bVal:PTR REAL8
;includeE:\Vsource\masm32\INCLUDE\windows.inc
;includeE:\Vsource\masm32\INCLUDE\user32.inc
;includeE:\Vsource\masm32\INCLUDE\kernel32.inc
PUBLICppow10
.CODE
;DllEntryproc hInstance:HINSTANCE, reason:DWORD, reserved1:DWORD
;.if reason==DLL_PROCESS_ATTACH
;invoke MessageBox,NULL,addr LoadMsg,addr AppName,MB_OK
;.elseif reason==DLL_PROCESS_DETACH
;invoke MessageBox,NULL,addr UnloadMsg,addr AppName,MB_OK
;.elseif reason==DLL_THREAD_ATTACH
;invoke MessageBox,NULL,addr ThreadCreated,addr AppName,MB_OK
;.else ; DLL_THREAD_DETACH
;invoke MessageBox,NULL,addr ThreadDestroyed,addr AppName,MB_OK
;.endif
;mov eax,TRUE
;ret
;DllEntryEndp
;FUNCTION _Ppow10( double val, double pow: ) : Extended;
;_TEXTSEGMENT WORD PUBLIC 'CODE'
;ppow10 PROC,aVal:PTR REAL8, bVal:PTR REAL8
;ppow10 PROC,aVal:* Qword, bVal:Qword
ppow10PROC near
XUEQU 8 ; for eip & ebp
XDEQU 0 ; for edi, esi, ebx, ecx, edx
fp_powerEQU QWORD PTR [ebp+XU+8]
fp_valEQU QWORD PTR [ebp+XU]
valEQU QWORD PTR [eBP-XD-8] ; USE STACK
powerEQU QWORD PTR [eBP-XD-16] ; USE STACK
pow10EQU QWORD PTR [eBP-XD-24] ; USE STACK
FPower10:
pushebp
movebp,esp
;push edi
;push esi
;push eax
;push edx
subesp,24
FINIT
fldz
fstval
fstpower
fstppow10
                 MOV    EAX,8                 MOV    EDX,8; fldpi
              fld      fp_val   ;st(0)=val; fld aVal;st(0)=val
fstval
;fld Arg2 ;st(0)=power
;fstp power
;fld val ;st(0)=val
;fmul val ;st(0)=val*val
;fmul val ;st(0)=val*va*val
;fadd st,st(0)
;fmul qword ptr [ebp+16] ;st(0)=power
;fadd st,st(0)
;fwait
addesp,24
;pop edx
;pop eax
;pop esi
;pop edi
movesp,ebp
popebp
;leave ; @@@@@@ important don't use leave in vc++ 2010
RET;return value = st(0)
ppow10ENDP
;_TEXTENDS
END
;END DllEntry




欢迎光临 【阳光飞狐__与财富同行】 (http://bbs.88158.cn/) Powered by Discuz! X3.2