Hi all,

Sorry for the stupid question but I can't figure it out. I'm starting a brand new project and don't have to worry about any legacy code. I'd like to produce a DLL and can't figure out how to tell VS 2005 which class to export.

If I try to use the method I know ( __declspec(dllexport) ) I get an error saying I can't use it on a managed class.

I'm embarassed to tell you how long I've searched through documentation...So, how do I tell VS 2005 which classes to export


Re: Visual C++ General Managed C++ in a DLL

Bruno van Dooren

Hi there,

If your dll is a native dll project (no .NET bindings) then classes can be exported with __declspec(dllexport) .

However, if your dll is a .NET dll, then you don't have to do anything special to export those classes. the only thing you need to do is to mark them public, and they will be exported automatically.

applying __declspec(dllexport) to a C++/CLI class is indeed not possible because __declspec(dllexport) is a native thing, not a .NET thing.

Re: Visual C++ General Managed C++ in a DLL


How then do I use classes from the DLL

I have a VS project called PCSTools that has a class defined like this:

namespace BauerControls {

namespace PCSTools {

public ref class StringTools sealed





static void StrToChar(String ^ Strval, char * Charbuff, long buffsize);

static char *StrToChar(String ^Strval);

static char *StrToChar(String ^Strval, long CharSize);

static wchar_t *StrToWChar(String ^Strval);

static wchar_t *StrToWChar(String ^Strval, long CharSize);

static String ^WCharToStr(const wchar_t *Source);

static String ^CharToStr(const char *Source);

static int StrLen(const char* source);

static int PCSSubString(String ^input, long startindex, long count, String ^output);


}} // Namespaces

In another project, AnalysisEditor, I have it depend on the PCSTools project.

Then if I use statements like

using namespace BauerControls:Stick out tongueCSTools; //Generates: error C2039: 'PCSTools' : is not a member of 'BauerControls'

If I then delete the using namespace lines like the following don't compile...

StringTools:Tongue TiedtrToChar(txtName->Text, ReturnName, MAX_TESTPOINT_NAME_LENGTH); //Generates: error C2653: 'StringTools' : is not a class or namespace name

If I set the 'Ignore Import Library' option in the PCSTools linker options to 'No' nothing changes...execpt that if I comment out the references to StringTools (so things compile) I get a linker error:

LINK : fatal error LNK1104: cannot open file '..\..\build\vcntexec\PCSTools.lib'

So, I'm stumped. In the IDE, Intellisense can see the BauerControls and the PCSTools namespaces. However, I can't see anything in the PCSTools namespace. I don't know if that's related or not...


Re: Visual C++ General Managed C++ in a DLL

Ramkrishna Pawar

You just need to refer to the assembly in order to use it from Visual Studio, here is description on that,

Understanding and Using Assemblies and Namespaces in .NET

Add Reference Dialog Box

Re: Visual C++ General Managed C++ in a DLL


Excellent, thank you!