Hi everyone
There is a C# project which calls C++/CLI dll to be able to call
native C++ including templates. But the C++/CLI code itself also
requires the C# dll to get the types. For example:
C#:
class Test1
{
void Write()
{
Test1Native::Write(this);
}
}
C++/CLI:
class Test1Native
{
static void Write(Test1^ obj)
{
// calls to some global template and other native C++ functions
here.
}
}
This creates a build inter-dependency problem since the C++/CLI
requires the C# dll while the C# code requires the C++/CLI dll.
Currently i have a couple of possible approaches:
* Repeated builds with different configurations. To do this place the
C# code that calls the C++/CLI code in #if which is unset in the first
build pass, then C++/CLI dll is built and finally build C# again with
the macro defined. This is not nice especially since we shall just be
providing the library with no say on the applications' build
procedure.
* Call Test1Native::Write using reflection from C# to break the
compile time dependency -- this one does not appear very clean either
and shall incur a small overhead (though probably negligible) when
done multiple times.
Is there some other known way to deal with such situations?
Thanks. 7 4566
There is a C# project which calls C++/CLI dll to be able to call
native C++ including templates. But the C++/CLI code itself also
requires the C# dll to get the types. For example:
Hi,
Choose door number 3: split the C# project into 2 parts so that the C++/CLI
project and the C# project depend on a common C# class library.
That way your dependencies are tree shaped instead of circular.
If that is really not an option, I'd go for reflection because at least you
can wait until runtime to satisfy the dependencies.
Normally I really don't like shifting problems from build time to runtime,
but cyclical building dependencies are even uglier.
Kind regards,
Bruno van Dooren MVP - VC++ http://msmvps.com/blogs/vanDooren
Thanks for the reply.
I guess the third option would not be possible (e.g. the real life
class is quite close to the example i have given where the Test1.Write
is a virtual function). Reflection seems to be only real alternative
then.
regards,
sumedh.
On Mar 12, 4:04 pm, "Bruno van Dooren"
<bruno_nos_pam_van_doo...@hotmail.comwrote:
There is a C# project which calls C++/CLI dll to be able to call
native C++ including templates. But the C++/CLI code itself also
requires the C# dll to get the types. For example:
Hi,
Choose door number 3: split the C# project into 2 parts so that the C++/CLI
project and the C# project depend on a common C# class library.
That way your dependencies are tree shaped instead of circular.
If that is really not an option, I'd go for reflection because at least you
can wait until runtime to satisfy the dependencies.
Normally I really don't like shifting problems from build time to runtime,
but cyclical building dependencies are even uglier.
Kind regards,
Bruno van Dooren MVP - VC++ http://msmvps.com/blogs/vanDooren
"Sumedh" <su*****@gmail.comwrote in message
news:11**********************@q40g2000cwq.googlegr oups.com...
Thanks for the reply.
I guess the third option would not be possible (e.g. the real life
class is quite close to the example i have given where the Test1.Write
is a virtual function). Reflection seems to be only real alternative
then.
Define an interface in the C++/CLI assembly, that the C# client must
implement and pass in. In your specific example, the only reverse call is
to a function, so you can use a delegate instead of a full interface. The
delegate can either be passed to C++ as an argument to each function needing
it, or stored as a static variable/property of one of the C++ classes.
>
regards,
sumedh.
On Mar 12, 4:04 pm, "Bruno van Dooren"
<bruno_nos_pam_van_doo...@hotmail.comwrote:
There is a C# project which calls C++/CLI dll to be able to call
native C++ including templates. But the C++/CLI code itself also
requires the C# dll to get the types. For example:
Hi, Choose door number 3: split the C# project into 2 parts so that the C++/CLI project and the C# project depend on a common C# class library. That way your dependencies are tree shaped instead of circular.
If that is really not an option, I'd go for reflection because at least you can wait until runtime to satisfy the dependencies.
Normally I really don't like shifting problems from build time to runtime, but cyclical building dependencies are even uglier.
Kind regards, Bruno van Dooren MVP - VC++ http://msmvps.com/blogs/vanDooren
I guess the third option would not be possible (e.g. the real life
class is quite close to the example i have given where the Test1.Write
is a virtual function). Reflection seems to be only real alternative
then.
Define an interface in the C++/CLI assembly, that the C# client must
implement and pass in. In your specific example, the only reverse call is
to a function, so you can use a delegate instead of a full interface. The
delegate can either be passed to C++ as an argument to each function needing
it, or stored as a static variable/property of one of the C++ classes.
Thanks, but didn't get this completely. The class will look something
like the following:
C#:
class Test1
{
public int First
{
get
{
return m_first;
}
}
public string Second
{
get
{
return m_second;
}
}
void Write()
{
Test1Native::Write(this);
}
}
C++/CLI:
void writeObject(Test1^ obj)
{
writeObject(obj->First); // writeObject is a global overloaded
template function
// some more calls to native C++ functions.
writeObject(obj->Second);
// some more calls to native C++ functions.
}
An interface for a particular class can be provided, but this needs to
be done for many different classes. So do you mean an interface for
each such class?
regards
sumedh
"Sumedh" <su*****@gmail.comwrote in message
news:11*********************@n33g2000cwc.googlegro ups.com...
I guess the third option would not be possible (e.g. the real life
class is quite close to the example i have given where the Test1.Write
is a virtual function). Reflection seems to be only real alternative
then.
Define an interface in the C++/CLI assembly, that the C# client must implement and pass in. In your specific example, the only reverse call is to a function, so you can use a delegate instead of a full interface. The delegate can either be passed to C++ as an argument to each function needing it, or stored as a static variable/property of one of the C++ classes.
Thanks, but didn't get this completely. The class will look something
like the following:
C#:
class Test1
{
public int First
{
get
{
return m_first;
}
}
public string Second
{
get
{
return m_second;
}
}
void Write()
{
Test1Native::Write(this);
}
}
C++/CLI:
void writeObject(Test1^ obj)
{
writeObject(obj->First); // writeObject is a global overloaded
template function
// some more calls to native C++ functions.
writeObject(obj->Second);
// some more calls to native C++ functions.
}
An interface for a particular class can be provided, but this needs to
be done for many different classes. So do you mean an interface for
each such class?
Yes.
That's the only way to unravel the dependency. However, I understood that
your customers would write custom code calling your C++/CLI assembly? In
that case you had better provide a clean set of API interfaces.
>
regards
sumedh
Yes.
That's the only way to unravel the dependency. However, I understood that
your customers would write custom code calling your C++/CLI assembly? In
that case you had better provide a clean set of API interfaces.
Thanks. Normally the client code will call the C# assembly and not the
C++/CLI assembly directly. Providing an interface for each class seems
to be the cleanest way.
regards
sumedh
Yes.
That's the only way to unravel the dependency. However, I understood that
your customers would write custom code calling your C++/CLI assembly? In
that case you had better provide a clean set of API interfaces.
Thanks. Normally the client code will call the C# assembly and not the
C++/CLI assembly directly. Providing an interface for each class seems
to be the cleanest way.
regards
sumedh This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David M. Karr |
last post by:
I've been asked to help debug a complex problem involving inter-frame
references, so I just want to understand the elements involved with
this.
Apparently, there is a page with multiple frames,...
|
by: Frank Meng |
last post by:
Hi.
I am trying a csharp sample from
http://www.codeproject.com/csharp/socketsincs.asp .
(Sorry I didn't post all the source codes here, please get the codes
from above link if you want to try)....
|
by: Viper Venom |
last post by:
Dear All:
I am trying to write an application that consist 2 executables
1) Server.exe
2) Client.exe
I start the server.exe first and then start the two client exe by code and
kill both of...
|
by: A.M |
last post by:
Hi,
What is the best way to implemet Inter Process Communication in .NET ?
I developed two programs and I want to have them talk to each other.
Thanks,
Alan
|
by: Bern McCarty |
last post by:
I have run an experiment to try to learn some things about floating point
performance in managed C++. I am using Visual Studio
2003. I was hoping to get a feel for whether or not it would make...
|
by: les |
last post by:
Here's a class which uses 2.0 generics to implement an inter-thread
message queue in C#. Any number of threads can post and read from the
queue simultaneously, and the message object can be any...
|
by: Hugo Ferreira |
last post by:
Hi everyone!
Here's the current scenario: I have a program in Python that computes
something very fast (<1s), but it takes a considerable amount of time
to read the startup data (>90s). Since...
|
by: Laurence |
last post by:
Hi folks,
As I konw: database partition (aka data partition?), the database can
span multiple machines; table partition, the data within a table can
seperate by certain condition.
How about...
|
by: halekio |
last post by:
Hi all,
Please bear with me as I've only started programming in C# 2 weeks ago
and this is my first contact with OOP.
I ran into a situation where I needed to catch an event in an object
that...
|
by: dantz |
last post by:
After reading all of the materials in msdn about interprocess communication
now I am confused. I hope someone can give me some enlightment.
I am developing a multithreaded client-server...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |