473,748 Members | 10,889 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inter-dependency between C++/CLI and C# dlls

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::Wr ite(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::Wr ite 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.

Mar 12 '07 #1
7 4594
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

Mar 12 '07 #2
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...@hotm ail.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

Mar 12 '07 #3

"Sumedh" <su*****@gmail. comwrote in message
news:11******** **************@ q40g2000cwq.goo glegroups.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...@hotm ail.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


Mar 12 '07 #4
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::Wr ite(this);
}
}

C++/CLI:

void writeObject(Tes t1^ 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

Mar 12 '07 #5

"Sumedh" <su*****@gmail. comwrote in message
news:11******** *************@n 33g2000cwc.goog legroups.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::Wr ite(this);
}
}

C++/CLI:

void writeObject(Tes t1^ 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

Mar 12 '07 #6
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

Mar 13 '07 #7
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

Mar 13 '07 #8

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

Similar topics

1
1823
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, where one of the frames is a "hidden" frame, and is there just to contain one or more "fields" that are referenced from other frames. Supposedly, if a user "sits" somewhere in this set of pages for several minutes and then tries to do...
4
3854
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). I had some troubles when I started 6 threads (each thread made a separate connection) and sent messages to same server simultaneously. Sometimes, not always, the socket looks like ok, but really it is dead. I don't why it happens.
4
4962
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 the client when the server exit (This is already done)
7
31704
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
13
4150
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 sense to punch out from managed code to native code (I was using IJW) in order to do some amount of floating point work and, if so, what that certain amount of floating point work was approximately. To attempt to do this I made a program that...
6
16717
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 type. There's a test driver at the bottom which demonstrates usage. /*-----------------------------------------------------------------------------------------------------*/ using System; using System.Collections.Generic;
0
1878
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 the startup data is pretty static, I want this program to be resident and ready in memory all the time. The client-side of this program is a function in PostgreSQL. For the sake of simplicity, let's assume it is another program in Python that
1
4966
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 inter-partition and intra-partition? Is inter-partition database partition...?
1
4160
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 had no connection or reference to the object that triggered it. It goes something like this: (not syntactically correct..it's just for the idea)
0
2323
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 application which communicates via HTTP Request using HTTPListener/HTTPWebRequest. The server(which is the focus of my question) will be having different modules. I want these modules to communicate with each other using the fastest IPC but I can't figure...
0
8991
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
8830
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9541
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...
1
9321
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
9247
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
8242
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
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3312
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

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.