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{


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


		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)?

6 Years
Discussion Span
Last Post by Ancient Dragon

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.

Votes + Comments
Succint information to answer the question. Much obliged!

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 = "";

			return s;
			solved = es_solve(s);
			return solved.c_str();

	void setMode(const char* s){

			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.

Edited by Intrade: n/a


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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.