Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

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.

C++
#pragma once
#using<mscorlib.dll>
#using<system.windows.forms.dll>
// 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
    {
    public:
        test(void)
        {

        };
        void ShowMessage()
        {
            MessageBox::Show("Hello World");
        }
    };
}




Shashi
Posted
Updated 13-Oct-11 5:30am
v3
Comments
Sergey Alexandrovich Kryukov 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..?
--SA
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.
Sergey Alexandrovich Kryukov 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). :-)
--SA

They certainly can. You miss something.

—SA
 
Share this answer
 
Comments
Espen Harlinn 13-Oct-11 17:48pm    
Right :)
Sergey Alexandrovich Kryukov 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.
--SA
You probably need to use
C#
#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
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 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?
--SA
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900