Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2005

Tip: Looking for answers? Try searching our database.

Two Dlls, Same Namespace, Cast Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rob - 04 Jul 2005 00:15 GMT
I have two projects (dlltest, dll2) both creating a dll. The two dlls
define classes (dll1, dll2) within the same namespace (MyNamespace).
One of the dlls (dlltest) is using functionality of the other dll
(dll2). Also both dlls use the same enum (MyEnum) defined in a header
file (common.h). This header file is included in both dlls.

Now I have one function from the first dll (dlltest) return the return
argument from the second dll (dll2). The compiler then complains:

error C2440: 'return' : cannot convert 'MyNamespace::MyEnum' to
'MyNamespace::MyEnum'.

It seems that because the include file is included in both dlls MyEnum
is considered as two different enums even if they reside in the same
namespace. Is this correct? If so then how can it distinguish between
the two if they are called the same? If not then what is the problem.

In any case, what is the proper solution to this? Maybe I could combine
everything in one dll but the functionality of dll2 really can stand on
it's own feet so throwing dlltest into the dll2 does not seem proper.
Also in the actual project there are other dlls that can live
bythemselves but they have some common types. So I am really not sure
how to solve this problem (technically and conceptually). Any ideas are
welcome.

common.h
---------

#ifndef _COMMON_H
#define _COMMON_H
enum class MyEnum{
     enum1,
     enum2,
     enum3
};
#endif

dll2
---
using namespace System;
namespace MyNamespace{
     #include "../dlltest/common.h"

     public ref class dll2{
     public:
           static MyEnum ReturnEnumDll2(){
                 return MyEnum::enum1;
           }
     };
}

dlltest
------
using namespace System;
#using <dll2.dll>
namespace MyNamespace {
     #include "common.h"

     public ref class dll1 {
           MyEnum ReturnEnumDll1(){
                 return dll2::ReturnEnumDll2();
           }
     };
}

Regards,
Rob
Tamas Demjen - 06 Jul 2005 19:41 GMT
> error C2440: 'return' : cannot convert 'MyNamespace::MyEnum' to
> 'MyNamespace::MyEnum'.
[quoted text clipped - 3 lines]
> namespace. Is this correct? If so then how can it distinguish between
> the two if they are called the same? If not then what is the problem.

I don't think you should include managed declarations between assemblies
(DLLs). You should be doing #using instead or #include. Declare the enum
in one of the DLLs only. So #include from dll2, but #using from dlltest,
remove the #include from there. This, of course, requires that you make
MyEnum public:

public enum class MyEnum{
      enum1,
      enum2,
      enum3
};

Tom

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.