Hi there,

Could someone give me a simple of example of how to write code in a c++ class library file? I made this to include through a reference in a c# app file. This is what Ive tried but Ive gotten all sorts of build errors:

// CClass.h

#pragma once

using namespace System;

namespace CClass {

	public ref class Class1
	{
		string nombre;
	public: 
		Class1()
		{
			nombre= "None";
			cout<<nombre<<endl;
		}
		~Class1(){}
		void setNombre(string n)
		{
			nombre= n;
		}
		string getNombre()
		{
			return nombre;
		}

	};
}

Thanks in advance for your help!
Drue

Sorry I forgot to put that it was in Visual Studio 2008. A class library (if I understand correctly) is a class that is turned into a dll that can be accessed through a reference by an executable. For example, I should be able to make a class library in C++ and then later call it from a C# method. Its one of the ways to combine code from different programming languages in Visual Studio.

I hope it makes more sense now :)

I had a same question some days ago and it went unanswered. I could not complain as I pay no body and I don't get paid. All is voluntary and I hope someone knowledgeable will step in. I haven't done that and I plan to do. Once I get anywhere I will post here

when u start doing any project in VS u have specify what kind of project u r going to do.

so if you want to make a DLL ther is an option to do that..
only extra thing u need to do in your code is exporting the symbols which u want out . that u can find on net decal_export or somthing like that i dont actually remember...

My (rustly) recollection from 3-4 years ago is that you need to make a class library project in your solution (I am assuming you're using visual studio)

File -> New -> Project... -> Select "CLR" From Tree -> Select "Class library" from the right hand pane.

Fill in the name and press ok.
Develop your class.

Then in you normal projects you just add your class library either

1. If your normal project is in the same solution as the class library by selecting the project (useful for debugging since they both get built using the same configuration)
2. By selecting the output DLL of your class library project.

This article has been dead for over six months. Start a new discussion instead.