Click here to Skip to main content
13,004,446 members (75,900 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I have a old native MFC/c++ dll I have managed to get it compiled with /CLR flag.
Now I have added a managed C++/CLI class to the dll within a namaspace.

The header file is below, and the cpp file only has #include for the header file.
The native dll is a huge dll project with lot of un managed code, but it has only one managed c++ class like below.

When I add that dll as a reference to a .net winforms project I don't see that namespace / class, in the object browser,

and I get compile error for not finding the namespace "ShashiTest"

I am using Visual studio 2008.

Native dlls in mixed mode can not be added as reference to a managed project ?

Or am I missing something

Please help.

#pragma once
// Class derived from Forms
using namespace System::Windows::Forms;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Diagnostics;
using namespace System::Windows::Forms;
namespace ShashiTest {
    /// <summary>
    /// Summary for test
    /// </summary>
    public ref class test
        void ShowMessage()
            MessageBox::Show("Hello World");

Posted 12-Oct-11 18:33pm
Updated 13-Oct-11 5:30am
SAKryukov 13-Oct-11 1:18am
Please show this class. Please simplify code to bare minimum (one class, one namespace, one, method) but show the whole page. Wrong syntax, not really C++/CLI? Missing implementation? What else..?
Philippe Mori 13-Oct-11 8:34am
The DLL must be compiled before Intellisence shows any C++ code... and it does not always properly works (Intellisence does not always see everything it should from C++/CLI DLL). However, if the code is correct the application will build anyway.

Does the managed project is in C# or C++/CLI? And which version of Visual Studio are you using?

If the DLL is itself dependant on other DLLs, it might be even worst if other DLLs are not found.
SAKryukov 13-Oct-11 15:17pm
You see, when you add a referenced DLL, you can click on it node in VS Solution Explorer; and its managed declarations will be immediately shown using Reflection in the browser.
Another question to OP: did you do it? The class you added to the question (thank you for update) looks correct and should be exposed.
You miss something (else). :-)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

They certainly can. You miss something.

Espen Harlinn 13-Oct-11 17:48pm
Right :)
SAKryukov 13-Oct-11 19:36pm
Thank you, Espen.
The problem is not resolved yet, as OP posted a piece of code where there is nothing wrong. I suggested to look more thoroughly, please see my new comment to the answer.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

You probably need to use
#pragma managed(push,off)
// Unmanaged code goes here
#pragma managed(pop)

See Using ACE with C++ CLI[^] for a working example.

Best regards
Espen Harlinn
SAKryukov 13-Oct-11 19:38pm
Very good point, and article, my 5. Maybe OP already have mixed assembly with managed code but just fail to see it?
Espen Harlinn 14-Oct-11 6:36am
Possibly, thanks Sergey!
Simon Bang Terkildsen 14-Oct-11 18:41pm
Great article.
Espen Harlinn 15-Oct-11 4:16am
Thank you, Simon!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170627.1 | Last Updated 13 Oct 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100