What I want to know is if I can call a function defined in a C++ class in Visual Basic through a .dll generated from VC++2010?

Is this possible, or do I need to define the .dll with C++ raw functions outside of a class?

For example, my class looks like this--

//...

typedef class EquationSolver{

	private:

		static int mode;
		static bool isProperEquation(string);
		static string _solve(string);
		static enum {MODES_SUPPORTED = 1};

	public:

		static __declspec(dllexport) string solve(string);
		static __declspec(dllexport) void setMode(string);
		static __declspec(dllexport) void setMode(size_t);
} ES;

int ES::mode = 0;

//...

Will I be able to call any of the public functions in VB, or do I have to write it using C-like function definitions (basically outside of a class and global variables)?

VB can not call the methods that take c++ classes as parameters or return values, such as std::string. And VB will have to call the methods by their mangled names as generated by the c++ compiler.

commented: Succint information to answer the question. Much obliged! +2

Should I worry about namespacing when porting the code, or should I omit that as well? For example--

namespace EquationSolver{

	static int mode = 0;
	static bool isProperEquation(string);
	static string es_solve(string);
	static enum {MODES_SUPPORTED = 1};
	static string solved = "";

	__declspec(dllexport) const char* solve(const char*);
	__declspec(dllexport) void setMode(const char*);
	__declspec(dllexport) void setMode(int);


	bool isProperEquation(string equation){

		return false; // TODO determine invalid input
	}

	string es_solve(string equation){

		return ""; // TODO solve the problem
	}

	const char* solve(const char* s){

		solved = "";

		if(!EquationSolver::isProperEquation(s))
			return s;
		else{
			solved = es_solve(s);
			return solved.c_str();
		}
	}

	void setMode(const char* s){

		if(string(s).compare("N"))
			mode = 0;
		else mode = 0; // Only 1 mode is supported for now
	}

	void setMode(int m){

		mode = m < MODES_SUPPORTED ? ((m >= 0) ? m : 0) : MODES_SUPPORTED - 1;
	}
};

Whoops! Lag caused a double post, my apologies.

namespaces will complicate the name mangling. How names are mangled is compiler dependent -- there is no standard way that they do it. You will want to have your c++ compiler generate a map file which will contain the mangled names.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.