-2

I'm a C# programmer who hasn't used C++ since the pre-.Net days.

I have a C# .Net DLL that I use with other C# programs. In the calling program in Visual Studio I simply do an "Add Resource..." and a Using" statement in the code that calls into it and voilà! there it is.

Now I have a customer who wants to access our DLL in a Visual Studio 2010 C++ (CLI) program. So I want to make a practice C++ program that uses our DLL. What's the equivalent of Add Reference in a C++/CLI project and what do I put in the program to expose the namespace for my DLL? Where does the DLL have to physically be? In the Solution Explorer in Visual Studio for the C++ project I don't see the same things as I do in a C# project.

user316117
  • 7,971
  • 20
  • 83
  • 158
  • It's been a long time for me, too, but I think you'd have to make the DLL COM-compliant, regsvr32 that baby and then access it like a COM component. – David Hoerster Jan 30 '14 at 15:21
  • 1
    I doubt it's that complicated - modern C++ is a .Net (CLI/CLR) language. – user316117 Jan 30 '14 at 15:25
  • 1
    He is running in the .Net framework. This is all CLI, all .Net. There are lots of people who use .Net who prefer to program in C++. – user316117 Jan 30 '14 at 15:32
  • 1
    To be fair, there aren't many .NET developers who prefer to code in C++. It's doable, but is overly verbose. In my experience the only time people choose to do it is when they need to interface with a C++ or C library – Sean Jan 30 '14 at 15:50

2 Answers2

1

Right click on the project in Visual Studio, and select "References". You should have a dialog with a few references already attached ("System" and a few others perhaps). Click "Add New Reference" and browse to the assembly (or project if it's in the same solution) that you want to use.

D Stanley
  • 149,601
  • 11
  • 178
  • 240
  • Excellent. It looks different from a C# project so I didn't recognize it, but everything seems to be there. Yeah, I didn't think it would be hard but it's interesting how many people saw C++ and just assumed "unmanaged" and made this question harder than it was. Thanks! – user316117 Jan 30 '14 at 15:57
0

Have you read the knowledgebase on calling native (.net) code from c++? It is about Visual Studio 2005, but the process should be the same.

How to call a managed DLL from native Visual C++ code in Visual Studio.NET or in Visual Studio

And there is a related (identical) question on here as well:

using c# dll in project c++


Edit since I missed the bit where it's about a managed C++ project:

How to add references to a managed Visual C++ project

.NET references
.NET references point to shared assemblies. For example, the assembly System.Windows.Forms.dll is a standard assembly for accessing the Windows Forms classes. In order to use this assembly in a Managed C++ application, you simply have to reference it with a #using preprocessor directive, as shown here:

#using <System.Windows.Forms.dll>

Community
  • 1
  • 1
w5l
  • 5,341
  • 1
  • 25
  • 43
  • 1
    This isn't a managed/unmanaged situation. This is a current Visual Studio .Net C++ program so it's all managed. It's all CLI. – user316117 Jan 30 '14 at 15:29
  • 1
    If it is managed, it should offer you the "Add References" dialog just like C#. – w5l Jan 30 '14 at 15:35
  • 1
    Do you know this for a fact? I just created a new C++ CLR project (In Visual Studio 2010, New Project->Other Languages->Visual C++ -> CLR) for .Net 4.0 and I don't see it. – user316117 Jan 30 '14 at 15:51