Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Managed
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.
 
#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 12-Oct-11 19:33pm
Edited 13-Oct-11 6:30am
v3
Comments
SAKryukov at 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 at 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 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

They certainly can. You miss something.
 
—SA
  Permalink  
Comments
Espen Harlinn at 13-Oct-11 17:48pm
   
Right :)
SAKryukov at 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
Rate this: bad
good
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
  Permalink  
Comments
SAKryukov at 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 at 14-Oct-11 6:36am
   
Possibly, thanks Sergey!
Simon Bang Terkildsen at 14-Oct-11 18:41pm
   
Great article.
Espen Harlinn at 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
0 OriginalGriff 280
1 Sergey Alexandrovich Kryukov 279
2 CPallini 205
3 Maciej Los 162
4 Afzaal Ahmad Zeeshan 160
0 OriginalGriff 5,635
1 DamithSL 4,496
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 13 Oct 2011
Copyright © CodeProject, 1999-2014
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