tags:

views:

31

answers:

2

I have one C++/CLI project, a GUI application, which is compiled in mixed mode (managed+unmanaged). Now I want to write a custom user control using C# and compile it to become CSharpA.dll. my question is: Can this dll be used by my C++/CLI project easily? How would I do that?

+3  A: 

Yes. Just add a reference to it. You may find yourself wanting using namespace directives, which, like the C# using directive, will add classes in other namespaces into the search space.

Ben Voigt
if i add the C# ctrl dll into my Cli/c++ project ,another question is can i see ctrl in the ToolBox page , can i drag the C# ctrl into my cli/C++ form visibly?
Biwier
As long as the control is public, you should find it in the toolbox. IIRC, Visual Studio automatically creates a new group in the toolbox for controls in the current project, but for referenced control libraries you might have to right-click the toolbox and add the library content.
Ben Voigt
acturally, i ever created one user control in Cli/C++ but didn't see this item in toolbox..
Biwier
if i do this in C# that's OK just like what you described.
Biwier
@Biwier: I'm getting lost trying to understand what you are getting to work and what doesn't. Please be clear about: What language the control library is written in, whether you are trying to find the control in the toolbox when building a form in the same project, different project same language, or different project different language. And then whether it's showing up for you the way you want.
Ben Voigt
here is what i did in my Cli/C++ program: I created A project, and in the A project, i created a Form named bform and a user control named cComtermizedCtrl , and i compiled the project successfully ,but I coundn't find the cComtermizedCtrl control in toolbox. why? i did the same thing in C# , I could find a new control was added into toolbox automatically after compiling.
Biwier
question 2: how can i add the cComtermizedCtrl into toolbox so that I can drag the control into bform visibly?
Biwier
A: 

You only have to compile your C# code into an assembly, and this assembly can be referenced from your C++/CLI App as any other assembly.

Maupertuis