Hi,

I'm new to c++ forum and to c++. I'll try to be as clear as possible.

What I'm trying to do:
(1) Make C++ read a CSV file to set some variable.
(2) C++ have to use those variable in some function. (Not a problem)
(3) Export those function in a DLL file which will be call in Excel (via VBA)

I must note that I can make both link (1) and (3) separately. But when I try to put both "link" in one code, Excel crash every time I run the function in it. The "Full" link I'm trying to make doesn't work... why?!

About the C++ code :
-The following code compile in Code::Blocks, but as said before, the DLL make Excel crash.
-The exported function "TPC" is kinda useless, I just pick it up for the example
-The File Parametre.csv is as follow:

FirstVar,12
SecondVar,8
ThirdVar,20

.h File

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <gsl/gsl_rng.h>
#include <ctime>
#include <cstdlib>
#include "windows.h"

using namespace std;

typedef vector <double> record_t;
typedef vector <record_t> data_t;

istream& operator >> ( istream& ins, record_t& record )
{
record.clear();
string line;
getline( ins, line );
stringstream ss( line );
string field;
while (getline( ss, field, ',' ))
{
stringstream fs( field );
double f = 0.0;
fs >> f;
record.push_back( f );
}

return ins;
}

istream& operator >> ( istream& ins, data_t& data )
{
data.clear();

record_t record;
while (ins >> record)
{
data.push_back( record );
}

return ins;
}

.cpp File

#include "header.h"
#define EXPORT __declspec(dllexport)

//-----------------------------------------------------------------------------
int RD(int i)
{
data_t data;
ifstream infile( "Parametre.csv" );
infile >> data;
if (!infile.eof())
{
cout << "Fooey!\n";
}
infile.close();
return data[i][1];
}

EXPORT double __stdcall TPC(int n)
{
double s=0;
for (int j=1; j<=n;j++)
{
s += j;
}
return s/RD(0);
}