473,395 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 11623
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.com

"François Côté" <Fr*******@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.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.com

"François Côté" <Fr*******@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.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*******@discussions.microsoft.com> schrieb im Newsbeitrag
news:F7**********************************@microsof t.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
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...
5
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
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
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
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...
4
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) ...
23
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? ...
3
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
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
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,...

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.