473,836 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# class forward declaration, possible?

I'm generating a TLB from one of my assemblies that contains an interface
declaration. The class that implements this interface is in another assembly.
I import this tlb in my C++ code to create instances of my C# classes. The
problem I have is that I need to specify the class in my CoCreate call in C++.

If I try to generate a TLB for the assembly that does contains the class and
interface implementation, I end up with a circular dependency problem between
my C++ and C# projects.

Is there any way I can declare the C# class along with the interface (a bit
like a IDL file) in that first assembly so the class is defined in the TLB?

Thanks,
Nov 16 '05 #1
3 11679
François,

I don't think that you need to change your C# code or the TLB produced
by calling TLBEXP. Rather, you need change how they are referenced in your
C++. If you are using the #import statement, then you can use the exclude
attribute to indicate what types to exclude (in this case, the interface
definition), as well as other attributes to control how the type information
is imported.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"François Côté" <Fr*******@disc ussions.microso ft.com> wrote in message
news:F7******** *************** ***********@mic rosoft.com...
I'm generating a TLB from one of my assemblies that contains an interface
declaration. The class that implements this interface is in another
assembly.
I import this tlb in my C++ code to create instances of my C# classes. The
problem I have is that I need to specify the class in my CoCreate call in
C++.

If I try to generate a TLB for the assembly that does contains the class
and
interface implementation, I end up with a circular dependency problem
between
my C++ and C# projects.

Is there any way I can declare the C# class along with the interface (a
bit
like a IDL file) in that first assembly so the class is defined in the
TLB?

Thanks,

Nov 16 '05 #2
Hi Nicholas and thanks for your quick reply,

So I guess the answer for forward declaration in C# is no?? :-)

The info you provided does not help me. The circular dependency is not a
*real* dependency because one of the dependency is for creating a COM objetc.

We had this same problem in C++ before: we have a utils dll that all other
dll have a real dependency on. At some point, we needed to call one of our
own COM object from this utils.dll Since the dll that hosted the COM object
depended on the utils dll, we couldn't just create a dependency in DevStudio.
Instead, we created a new project that contained the IDL file of the COM dll
and both projects depended (in DevStudio) on this IDL project. So the build
sequence was:

- the IDL project
=> creates the COM header file (interface + class definition)
- the Utils project (uses COM objects from next project)
- the COM implementation project (depends on Utils)

I have the exact same problem now (but with four Dlls, two in C# and two in
C++)

In C#, I have the interface in an assembly so it acts as an equivalent to
the IDL project above, except, because there is no class definition in the
resulting TLB, the next project in line can't compile.

If I could just add a class declaration to this assembly, my problem would
be solved, can it be done in C#?

Thanks for your support, it's really appreciated,
"Nicholas Paldino [.NET/C# MVP]" wrote:
François,

I don't think that you need to change your C# code or the TLB produced
by calling TLBEXP. Rather, you need change how they are referenced in your
C++. If you are using the #import statement, then you can use the exclude
attribute to indicate what types to exclude (in this case, the interface
definition), as well as other attributes to control how the type information
is imported.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"François Côté" <Fr*******@disc ussions.microso ft.com> wrote in message
news:F7******** *************** ***********@mic rosoft.com...
I'm generating a TLB from one of my assemblies that contains an interface
declaration. The class that implements this interface is in another
assembly.
I import this tlb in my C++ code to create instances of my C# classes. The
problem I have is that I need to specify the class in my CoCreate call in
C++.

If I try to generate a TLB for the assembly that does contains the class
and
interface implementation, I end up with a circular dependency problem
between
my C++ and C# projects.

Is there any way I can declare the C# class along with the interface (a
bit
like a IDL file) in that first assembly so the class is defined in the
TLB?

Thanks,


Nov 16 '05 #3
What about using an interface?

"François Côté" <Fr*******@disc ussions.microso ft.com> schrieb im Newsbeitrag
news:F7******** *************** ***********@mic rosoft.com...
I'm generating a TLB from one of my assemblies that contains an interface
declaration. The class that implements this interface is in another
assembly.
I import this tlb in my C++ code to create instances of my C# classes. The
problem I have is that I need to specify the class in my CoCreate call in
C++.

If I try to generate a TLB for the assembly that does contains the class
and
interface implementation, I end up with a circular dependency problem
between
my C++ and C# projects.

Is there any way I can declare the C# class along with the interface (a
bit
like a IDL file) in that first assembly so the class is defined in the
TLB?

Thanks,

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2789
by: Mon | last post by:
I am in the process of reorganizing my code and came across and I came across a problem, as described in the subject line of this posting. I have many classes that have instances of other classes as member variables. So including a forward declaration doesnt help, does it? Faced with these, I had the following options: -Include the appropriate header in the header file that contains the class definition that has a member variable that is...
5
9112
by: Stephane Routelous | last post by:
Hi, I would like to make a forward declaration of a strcuture nested in a class. I have file A.h class A { public: struct B
5
1944
by: Xiangliang Meng | last post by:
Hi, all. What are the benefit and the drawback of defining a class embedded inside another class? For example: class List { public:
4
3404
by: jonathanho15 | last post by:
Sometimes, when I browse through some code, I see declarations like: class SomeClass; These make absolutely no sense to me. Can anyone tell me what these kind of declarations do? Thanks!
2
4769
by: blueblueblue2005 | last post by:
Hi, there was a post several days ago about using forward class declaration to solve the circular including issue, today, one question suddenly came into mind: which class should the forward class declaration statement be in? suppose I have a class A and B, sample code as following: // A.h #ifndef A_H #define A_H
4
1389
by: Jerome | last post by:
Hi all, I'm trying to use forward declaration with value class but I don't succeed in compiling my (quite simple) sample code. This is my code I'm trying to compile (Visual Studio 2003) namespace managedDll { public __value class VecDouble; public __value class VecFloat
23
3874
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? Here's what I thought should work, but apparently doesn't: class Foo; void f1(Foo* p)
3
8864
by: yancheng.cheok | last post by:
hello all, how can i make, a forward declaration class's enum member, being visible by another class? consider the following case, ---------------------------- dog.h ----------------------------
3
3866
by: Juha Nieminen | last post by:
I once made my own smart pointer implementation for a project and at one point fought to death to find a malicious bug. The program was not working and I couldn't figure out why. The source of the problem was that MSVC++ was not giving me a warning even though it should have. The problem was that I was creating a smart pointer from a forward-declaration of a class which, it seems, makes it impossible for the smart pointer to call the...
0
9813
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10834
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10541
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10584
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10248
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4446
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3108
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.