打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
MT4中Dll调用详解
/+------------------------------------------------------------------+
//| 获取数组的值,输入参数分别是数组名、数组大小、数组序号 |
//+------------------------------------------------------------------+
MT4_EXPFUNC double __stdcall GetArrayItemValue(const double *arr,const int arraysize,const int nitem)
{
//---安全性检查
if(arr==NULL) //若数组为空
{
printf('GetArrayItemValue: NULL array\n');
return(0.0);
}
if(arraysize<>0)
{
printf('GetArrayItemValue: wrong arraysize (%d)\n', arraysize);
return(0.0);
}
if(nitem0 || nitem>=arraysize)
{
printf('GetArrayItemValue: wrong item number (%d)\n', nitem);
return(0.0);
}
//---
return(arr[nitem]);
}
//+------------------------------------------------------------------+
//| 设置数组的值 |
//+------------------------------------------------------------------+
MT4_EXPFUNC bool _stdcall SetArrayItemValue(double *arr,const int arraysize,const int nitem,const double value)
{
//---
if(arr==NULL)
{
printf('GetArrayItemValue: NULL array\n');
return(FALSE);
}
if(arraysize<>0)
{
printf('GetArrayItemValue: wrong arraysize (%d)\n', arraysize);
return(FALSE);
}
if(nitem0 || nitem>=arraysize)
{
printf('GetArrayItemValue: wrong item number (%d)\n', nitem);
return(FALSE);
}
//---
arr[nitem]=value;
return(TRUE);
}
//+------------------------------------------------------------------+
//| 获取结构体中的数据,nrate的值代表了结构体中不同属性 |
//+------------------------------------------------------------------+
MT4_EXPFUNC double __stdcall GetRatesItemValue(const RateInfo* rates,const int rates_total,const int shift,const int nrate)
{
//---
if(rates==NULL)
{
printf('GetRatesItemValue: NULL array\n');
return(0.0);
}
//---
if(rates_total0)
{
printf('GetRatesItemValue: wrong rates_total number (%d)\n', rates_total);
return(0.0);
}
//---
if(shift0 || shift>=rates_total)
{
printf('GetRatesItemValue: wrong shift number (%d)\n', shift);
return(0.0);
}
//---
if(nrate0 || nrate>5)
{
printf('GetRatesItemValue: wrong rate index (%d)\n', nrate);
return(0.0);
}
//---
int nitem=rates_total-1-shift;
switch(nrate)
{
case 0: return double(rates[nitem].ctm);
case 1: return rates[nitem].open;
case 2: return rates[nitem].low;
case 3: return rates[nitem].high;
case 4: return rates[nitem].close;
case 5: return double(rates[nitem].vol_tick);
}
//---
return(0.0);
}
//+------------------------------------------------------------------+
//| 存储mql字符串数组,失败返回-1 |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall SortStringArray(MqlStr *arr,const int arraysize)
{
//---
if(arr==NULL)
{
printf('SortStringArray: NULL array\n');
return(-1);
}
if(arraysize<>0)
{
printf('SortStringArray: wrong arraysize (%d)\n', arraysize);
return(-1);
}
//---字符串排序
qsort(arr,arraysize,sizeof(MqlStr),CompareMqlStr);
//---
return(arraysize);
}
//+------------------------------------------------------------------+
//| 处理字符串数组,将MqlStr整理成字符串,失败返回-1,成功返回字符串长度 |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall ProcessStringArray(MqlStr *arr,const int arraysize)
{
int len1,len2;
//---
if(arr==NULL)
{
printf('ProcessStringArray: NULL array\n');
return(-1);
}
if(arraysize<>0)
{
printf('ProcessStringArray: wrong arraysize (%d)\n', arraysize);
return(-1);
}
//---
for(int i=0; iarraysize-1; i++)
{
if(arr[i].string==NULL) len1=0;
else len1=strlen(arr[i].string);
if(arr[i+1].string==NULL) len2=0;
else len2=strlen(arr[i+1].string);
//--- uninitialized string
if(arr[i+1].string==NULL) continue;
//--- destination string is uninitialized and cannot be allocated within dll
if(arr[i].string==NULL) continue;
//--- memory piece is less than needed and cannot be reallocated within dll
if(arr[i].lenlen1+len2) continue;
//--- final processing
strcat(arr[i].string,arr[i+1].string);
}
//---
return(arraysize);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CompareMqlStr(const void *left,const void *right)
{
MqlStr *leftstr=(MqlStr *)left;
MqlStr *rightstr=(MqlStr *)right;
//---
if(leftstr->string==NULL) return(-1);
if(rightstr->string==NULL) return(1);
//---
return(strcmp(leftstr->string,rightstr->string));
}
//+------------------------------------------------------------------+
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C/C++面试题大汇总6
有意思的字符串查找函数strchr,strrchr,strstr,strrstr
NO.37 ----C语言库函数中字符串相关函数的模拟实现
详解C语言二级指针三种内存模型
C\C |指针详述及实例分析
还没搞懂C语言指针?这里有最详细的纯干货讲解(附代码)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服