Problems with DLL's in VC++ 10


Mario Biondini
10-16-2013, 01:31 PM
I am trying to construct a dll (fsodll) using Microsoft VC++ v. 10 and I getting thee errors listed below. The curious thing is that I do not get any of these errors when I build an executable, which is built and run OK. So it cannot be the code. May be I am doing something wrong with the dll. I list the errors and pertinent files (or the important parts below). Any help is welcome.
1> stdafx.cpp
1>c:\research_data\numerical recipies 3rd edition\code\incgammabeta.h(100): warning C4003: not enough actual parameters for macro 'min'
1>c:\research_data\numerical recipies 3rd edition\code\incgammabeta.h(100): error C2589: '(' : illegal token on right side of '::'
1>c:\research_data\numerical recipies 3rd edition\code\incgammabeta.h(100): error C2059: syntax error : '::'
1>c:\research_data\numerical recipies 3rd edition\code\incgammabeta.h(100): error C2059: syntax error : ')'
1>c:\research_data\numerical recipies 3rd edition\code\incgammabeta.h(100): error C2059: syntax error : ')'
1>c:\research_data\numerical recipies 3rd edition\code\incgammabeta.h(243): warning C4003: not enough actual parameters for macro 'min'
1>c:\research_data\numerical recipies 3rd edition\code\incgammabeta.h(243): error C2589: '(' : illegal token on right side of '::'
1>c:\research_data\numerical recipies 3rd edition\code\incgammabeta.h(243): error C2059: syntax error : '::'
1>c:\research_data\numerical recipies 3rd edition\code\incgammabeta.h(243): error C2059: syntax error : ')'
1>c:\research_data\numerical recipies 3rd edition\code\incgammabeta.h(243): error C2059: syntax error : ')'

Stdafx.h:

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#include "targetver.h"

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>

// TODO: reference additional headers your program requires here

#include "nr3.h"
#include "sort.h"
#include "moment.h"
#include "gamma.h"
#include "erf.h"
#include "incgammabeta.h"
#include "stattests.h"
#include "fitab.h"
#include "svd.h"

Stdafx.cpp:

// stdafx.cpp : source file that includes just the standard includes
// fsodll.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"


Fsodll.h

// fsodll.h with fuzzy set ordination defined as exportable

#ifdef FSODLL_EXPORTS
#define FSODLL_API __declspec(dllexport)
#else
#define FSODLL_API __declspec(dllimport)
#endif

FSODLL_API void nrerror(char error_text[]);
FSODLL_API float *array(int lenght);
FSODLL_API double *darray(int lenght);
FSODLL_API int *iarray(int lenght);
FSODLL_API void free_array(float *v);
FSODLL_API void free_darray(double *v);
FSODLL_API void free_iarray(int *v);
FSODLL_API float **mmatrix(int row,int colum);
FSODLL_API double **dmmatrix(int row,int colum);
FSODLL_API int **immatrix(int row,int colum);
FSODLL_API void free_mmatrix(float **m,int row);
FSODLL_API void free_dmmatrix(double **m,int row);
FSODLL_API void free_immatrix(int **m,int row);
FSODLL_API int ***itmatrix(int row,int colum1, int colum2);
FSODLL_API float ***ftmatrix(int row,int colum1, int colum2);
FSODLL_API double ***dtmatrix(int row,int colum1, int colum2);
FSODLL_API void free_itmatrix(int ***m,int row,int colum1);
FSODLL_API void free_ftmatrix(float ***m,int row,int colum1);
FSODLL_API void free_dtmatrix(double ***m,int row,int colum1);

class FSODLL_API matrix {
protected:
struct matrep {
double **m; // Pointer to matrix
int r,c; // Rows and columns
int n; // Reference count
} * p;
public:
matrix(int rows=1,int columns=1,double initval=0); //Create matrix
matrix(const matrix &x); //Copy constructor
matrix(char * flag, int dimension); //Create identity matrix
matrix(char * flag, matrix &a); //Create a copy of matrix X
~matrix(); //Destructor
matrix operator=(const matrix &rvalue); //Matrix equality assigment
matrix operator+(const matrix &rvalue); //Matrix addition
matrix operator-(const matrix &rvalue); //Matrix substraction
matrix operator*(const matrix &rvalue); //Matrix multiplication
double & val (int row, int col); //Element selection
matrix inverse();
void ludcmp(matrix &indx,matrix &d);
void lubksb(matrix &indx,matrix &c);
};
FSODLL_API void fsocalc();
FSODLL_API void emptycells(matrix &D, int m, int p, char *name, ofstream &out);


// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

Fsodll.cpp:

// fsodll.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "fsodll.h"

#include <stdexcept>

using namespace std;

void fsocalc()
{
char Spname[80],Envname[80],Distname[80],outname[80],outname2[80],outname3[80];

// Create output and input files

ofstream out; // Output file
cout << "Enter name of output file" << endl;
cin >> outname;
out.open(outname);
if(!out)
{
puts("Cannot open output file");
exit(1);
}
.
.
Etc
}


void emptycells(matrix &D, int m, int p, char *name, ofstream &out)
{
// Check for empty rows or columns

double *colsum;
colsum=darray(p);
.
.
Etc
}

Mario Biondini
10-17-2013, 02:28 PM
Talking with the MS forum folks it appears that the min/max macros are being #defined by VC++ and the program thus is trying to call std::min/std::max. The way to get around this by using #define NOMINMAX in stdafx.h. Why it does not cause a problem when building an executable is somewhat of a mystery but probably some project setting is getting lost in the translation.