MQL5 dll 2 dim array (openwatcom)
//+------------------------------------------------------------------+
//| MQL5DLL Test.mq5 |
//| Copyright 2010, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2010, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#define COL 5
//---
#import "watcomdll1.dll"
void SomeFunction(void);
void fnFillArray(int &arr[],int arr_size);
void fnFillArray2(int &arr[][COL],int arr_size);
#import
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
int i,j;
//--- call for the array filling
int arr[];
string result="Array: ";
ArrayResize(arr,10);
fnFillArray(arr,ArraySize(arr));
for(i=0;i<ArraySize(arr);i++) result=result+IntegerToString(arr[i])+" ";
Print(result);
//--- call for the array2 filling
int arr2[][COL];
string result2="Array2: ";
ArrayResize(arr2,10);
Print("arr_size: ",ArrayRange(arr2,0)," COL:",ArrayRange(arr2,1));
fnFillArray2(arr2,ArrayRange(arr2,0));
/*
for(i=0;i<ArrayRange(arr2,0);i++)
for(j=0;j<COL;j++)
arr2[i][j]=i;
*/
for(i=0;i<ArrayRange(arr2,0);i++)
for(j=0;j<COL;j++)
result2=result2+IntegerToString(arr2[i][j])+" ";
Print(result2);
//---
}
//+------------------------------------------------------------------+
#ifndef __MAIN_H__
#define __MAIN_H__
#include <windows.h>
#define COL 5
/* To use this exported function of dll, include this header
* in your project.
*/
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
void DLL_EXPORT __stdcall fnFillArray(int *arr,const int arr_size);
void DLL_EXPORT __stdcall fnFillArray2(int arr[][COL],const int arr_size);
void DLL_EXPORT __stdcall SomeFunction(void);
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__
#include "main.h"
//+------------------------------------------------------------------+
//| Filling the array with values |
//+------------------------------------------------------------------+
void DLL_EXPORT __stdcall fnFillArray(int *arr,const int arr_size)
{
//--- check input variables
if(arr==NULL || arr_size<1) return;
//--- fill array with values
for(int i=0;i<arr_size;i++) arr[i]=i;
}
//+------------------------------------------------------------------+
//| Filling the array with values |
//+------------------------------------------------------------------+
void DLL_EXPORT __stdcall fnFillArray2(int arr[][COL],const int arr_size)
{
//--- check input variables
if(arr==NULL || arr_size<1) return;
//--- fill array with values
for(int i=0;i<arr_size;i++)
for(int j=0;j<COL;j++)
arr[i][j]=i;
}
//+------------------------------------------------------------------+
//| a sample exported function
//+------------------------------------------------------------------+
void DLL_EXPORT __stdcall SomeFunction(void)
{
MessageBoxA(0, "XXXX :)", "DLL Message", MB_OK | MB_ICONINFORMATION);
}
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}