Hi, I'm developing an MSX dll function using the Microsoft Visual Studio 2005 C++ IDE and have encountered a strange problem that I do not know how to fix.
Similarly to the "MyMov" example "C" dll function given in the MDK manual (Version 9.1), the dll function I'm writing uses a local function that does all of the complex calculations for the main dll function. Just like the "MovingAverage" local function of the "MyMov" dll function, my local function requires an integer number (i.e. "N") of input data values in order to calculate each output value. My local function currently uses a basic "for" loop to read each of the N input values it requires into a one-dimensional array of type double (I do all of the calculations in type double and then typecast the output to type float) and then calculates a single output data value using the input data values stored in the array.
I have been testing my dll function in Metastock using a fictional test security I have created using the Downloader. For ease of testing, the test security only has a sufficient number (i.e. N=20) of data values so that my dll function only outputs a single data value. The input data values as they are shown by the Downloader are exactly as follows: -6.42788, 0, 6.42788, 9.84808, 8.66025, 3.42020, -3.42020, -8.66025, -9.84808, -6.42788, 0, 6.42788, 9.84808, 8.66025, 3.42020, -3.42020, -8.66025, -9.84808, -6.42788, 0.
When I run my dll function in Metastock, the single value it outputs is incorrect. I know that the value it outputs is incorrect because I have developed a basic C++ console program (i.e. a program which runs independently of Metastock) which uses the same algorithm as the local function of my dll and which I know for a fact produces the correct output. The algorithm employed by my console program only differs from that of my local dll function in that instead of reading the input data from a Metastock security file, it reads it from a text file. Even though the data stored in the test file looks exactly the same as that listed above, the output value of my console program is different to that output by Metastock when it runs my dll.
Interestingly, I have found that if I explicitly intialise my local function array with the N input data values (see C++ code below) instead of reading the input data values from the Metastock security file, my dll function produces the correct output when it is run in Metastock.
x[0] = -6.42788; x[1] = 0; x[2] = 6.42788; x[3] = 9.84808; x[4] = 8.66025; x [ 5 ] = 3.4202; x[6] = -3.4202; x[7] = -8.66025; x[ 8] = -9.84808; x[9] = -6.42788; x[10] = 0; x[11] = 6.42788; x[12] = 9.84808; x[13] = 8.66025; x[14] = 3.4202; x[15] = -3.4202; x[16] = -8.66025; x[17] = -9.84808; x[18] = -6.42788; x[19] = 0;
Amongst other things, I have checked to make sure that the local function of my dll is correctly reading in the input data values into the data array, and I have also tried explicitly type-casting the input data to type double and type float. Nothing I have tried makes any difference.
It would be greatly appreciated if anyone can help.
Cheers,
Duffman