c++ custom DLL help

I have been trying to create a custom DLL to run in a program to go through existing data and create a new set of data that fits my criteria. The original set is composed of 1's and -1's. M goal for the second set is to alter the first set so that two instances never happen. If the column produces (1,-1,1) or (-1,1,-1) I then want it to change that third value to be equal to the second value and move on. Any help with this would be wonderful, this is what I have so far.

_declspec(dllexport) void input(double *series)

{
double *in, *out;

long int i, j;

in = series;
out = days;

for (i = 0; i<size; i++)
{
if Range(i) <> Range(i - 1) And Range(i) = Range(i - 2) Then
Range(i) = Range(i - 1)
}
in++; out++;
}
First of all, please use code tags. On the format menu, click the button that looks like "<>" and paste your code between them.

A few questions.

What do you mean by "If the column produces..."? What column is that? It looks like you are merely reading a stream of data. A column suggests a 2-D array.

Are you interested in any 3 consecutive values or values (0-2), (3-5), etc.?

What is Range? Where does size come from?

Other comments:

In your if statement, the first comparison should be !=, not "<>".

In the if statment, the second comparison is actually an assignment (=). You want a comparison (==)

I have no idea what you are trying to do with in and out.


I apologize for the sloppy nature of the code, I am pretty new to c++ and way over my head with this task. The reference to columns was from what I had done in VBA to solve this problem. I had a single column of data (column B) which in the DLL would be my single array of input data. My translation from VBA to c++ hasn't gone too well. I am only interested in the events in the input array where there is either (1,-1,1) or (-1,1,-1) in sequence. I want the output array to not contain any instances of this and instead set the third number equal to the second and loop. My VBA code that solved the problem was this
1
2
3
4
5
6
7
8
9
10
11
12
Sub alterdata()

Dim i As Long
Dim lr As Long

lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = 3 To lr
    If Range("B" & i) <> Range("B" & i - 1) And Range("B" & i) = Range("B" & i - 2) Then
        Range("B" & i) = Range("B" & i - 1)
    End If
Next
End Sub


This was referencing data in the B column and it was designed ensuring that there were no instances that I mentioned above. If it found one it would set the third number equal to the second number and loop again.

My first post was an attempt to re-create that in a c++ DLL however I am not very proficient in c++ or DLL's yet as you can see. Do you have any suggestions on what would be the best approach here?
If you are a beginner than start with a simple console app. Once you get this working you can convert it then in a DLL.

Here is some code to get you started. If you need more help then send me a PM.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>

using namespace std;

void AlterData(double *input, double *output, size_t size)
{
  // Your code here
}

void PrintData(double *data, size_t size)
{
  // your code here
}

int main(void)
{
  const int NUM_ELEMS = 3;

  double input[NUM_ELEMS] = { 1, -1, 1};
  double output[NUM_ELEMS] = {0};

  cout << "Original Data: ";
  PrintData(input, NUM_ELEMS);
  AlterData(input, output, NUM_ELEMS);
  cout << "\nModified Data: ";
  PrintData(output, NUM_ELEMS);

  system("pause");
  return 0;
}
Last edited on
Topic archived. No new replies allowed.