MQL5 dll 2 dim array copy (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);
void fnCopyArray2(int &arr1[][COL],int &arr2[][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 arr1[][COL];
int arr2[][COL];
string result1="Array1: ";
string result2="Array2: ";
ArrayResize(arr1,10);
ArrayResize(arr2,10);
for(i=0;i<ArrayRange(arr2,0);i++)
for(j=0;j<COL;j++)
{
arr2[i][j]=i;
result2=result2+IntegerToString(arr2[i][j])+" ";
}
fnCopyArray2(arr1,arr2,ArrayRange(arr2,0));
for(i=0;i<ArrayRange(arr1,0);i++)
for(j=0;j<COL;j++)
result1=result1+IntegerToString(arr1[i][j])+" ";
Print("array1->",result1);
Print("array2->",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 fnCopyArray2(int arr1[][COL],int arr2[][COL],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;
}
//+------------------------------------------------------------------+
//| Copy array2 to array1 |
//+------------------------------------------------------------------+
void DLL_EXPORT __stdcall fnCopyArray2(int arr1[][COL],int arr2[][COL],int arr_size)
{
//--- check input variables
if(arr1==NULL || arr2==NULL || arr_size<1) return;
for(int i=0;i<arr_size;i++)
for(int j=0;j<COL;j++)
arr1[i][j]=arr2[i][j];
}
//+------------------------------------------------------------------+
//| 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
}