Using C++ in C#, best suggestion in this situation?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I thought I would post here, as I am sure someone, somewhere has run into
this problem, and might have a good solution for me.

I am writing an applicaiton in C# that will accept data and then put it into
an Excel spreadsheet. Easy, right? Well it is, until you have to get the
data from another application that is written in Borland C++ PowerBuilder 5.

The situation is that the Borland Code isnt going to get re-written (too
expensive, couple million lines of code) so we have to develop in Borland
still to handle some things, and the ACE is being used for ease of
communication between compilers (it is basically platform independent).
Unfortunately, the ACE code is not written in C#, but in C++. So, my
application will have a C++ applicaiton that will be receiveing the data form
the Borland Code, and decoding the ACE, and then storing the data somewhere
(a class, a struct, a file, a stream... wherever is best) and then sending
this data to my C# code. I am expecting to use one class per distinct
message, and the messages wil continue to grow over time (thousands of
messages is not un-realistic) so I am also trying to find the least
maintenance heavy method to accomplish the task.

How would you recommend I get the data from my unmanaged C++ code and into
my C# application for quick stuffing into an Excel spreadsheet. Can it be
done is something close to real-time (maybe with a 1 - 2 second delay)?

Thanks in advance for any ideas, tips, hints, or suggestions.

Andrew S. Giles
 
You say "get the data", however you need to explain what sort of interfaces
this C++ program has.
For instance, does it expose COM objects?
Does it have to be invoked as a new process, and passed a switch in order to
tell it to send the results to a file? Does it just print its output, printf
style?
Does it have Win32 DLLs that can be P-Invoked?

If it doens't have *any* method of actually communicating the data to
another program, i.e. it just expects itself to be the end-user program, then
you will have to basically extract the code that gets the data you want, and
write an interface for it - the best bet would be a Win32 DLL, so that you
can PInvoke it from C#.

But in order to know how your C# program can get the data, you need to know
what data's on offer, and how...
 
Andrew,

I'm not sure what you mean by ACE. Also, I don't understand why you use
C# at all, if you already have a C++ application that is doing the heavy
work (the transformation). Instead of placing in yet another intermediary
format, why not have the C++ code just write the excel sheet?

If you really want to use managed code, you can do so within C++, that's
pretty easy, you just have to add a switch (I believe it is /clr).

Hope this helps.
 
Terribly sorry for incompleteness.

No, it does not expose a COM object, so the COM interop is not an option.
It is spawned as its own process (or will be) so that it may receive the
decoded messages from a clearinghouse. How it gets the data (contained in
the decoded message) from where the C++ code receives it and into my C# is
where I am a touch lost. I thought about writing it to a file, and then just
reading that file into C#, but am concerned with speed and disk space usage
or fragmentation (after I delete all of these temp files after reading them).
The code does not have Win32 DLLs to be P/Invoked.

I will have some control over how the data is sent out of the C++ package, I
just want to find the best way to handle it. Would it be a good idea to
write functions int he C++ to be called from the C# code that are passed the
necessary parameters that I need filled?

Andrew
 
Nicholas,

ACE is the Adaptive Communicaiton Environment
( http://www.cs.wustl.edu/~schmidt/ACE.html ).

My company is using it as a method to send messages between its array of
applications as needed. It was chosen because it is basically platform
independent.

The path for the data is roughly as follows: Some Borland code gets the
data from the hardware, and put it into a Class (this is Borland C++ code).
This Class is then put into an ACE message class, and sent out to wherever it
needs to go. There is an ACE gateway which sees this message, grabs it, and
routes it to an ACE consumer for use (the consumer is associated, in this
instance, with my code). The ACE consumer gets the ACE message, decodes it
to begin looking at the class (this is Visual C++ 6 code now). From here,
the data needs to get into my application for putting it into Excel (only
option at the moment, other options to follow, including Database, Crystal
reports, etc). I already have the interface that the user sees written in
C#, as well as the Export to Excel code in C#, which is why I would like to
not need to re-write it all over to C++.

Is re-writing the end-user app in Visual C++ 2003.NET the best way to go?

Nicholas Paldino said:
Andrew,

I'm not sure what you mean by ACE. Also, I don't understand why you use
C# at all, if you already have a C++ application that is doing the heavy
work (the transformation). Instead of placing in yet another intermediary
format, why not have the C++ code just write the excel sheet?

If you really want to use managed code, you can do so within C++, that's
pretty easy, you just have to add a switch (I believe it is /clr).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Andrew S. Giles said:
I thought I would post here, as I am sure someone, somewhere has run into
this problem, and might have a good solution for me.

I am writing an applicaiton in C# that will accept data and then put it
into
an Excel spreadsheet. Easy, right? Well it is, until you have to get the
data from another application that is written in Borland C++ PowerBuilder
5.

The situation is that the Borland Code isnt going to get re-written (too
expensive, couple million lines of code) so we have to develop in Borland
still to handle some things, and the ACE is being used for ease of
communication between compilers (it is basically platform independent).
Unfortunately, the ACE code is not written in C#, but in C++. So, my
application will have a C++ applicaiton that will be receiveing the data
form
the Borland Code, and decoding the ACE, and then storing the data
somewhere
(a class, a struct, a file, a stream... wherever is best) and then sending
this data to my C# code. I am expecting to use one class per distinct
message, and the messages wil continue to grow over time (thousands of
messages is not un-realistic) so I am also trying to find the least
maintenance heavy method to accomplish the task.

How would you recommend I get the data from my unmanaged C++ code and into
my C# application for quick stuffing into an Excel spreadsheet. Can it be
done is something close to real-time (maybe with a 1 - 2 second delay)?

Thanks in advance for any ideas, tips, hints, or suggestions.

Andrew S. Giles
 
Andrew,

You don't have to re-write it. You should be able to import the project
and then set the /clr flag and then use managed code.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Andrew S. Giles said:
Nicholas,

ACE is the Adaptive Communicaiton Environment
( http://www.cs.wustl.edu/~schmidt/ACE.html ).

My company is using it as a method to send messages between its array of
applications as needed. It was chosen because it is basically platform
independent.

The path for the data is roughly as follows: Some Borland code gets the
data from the hardware, and put it into a Class (this is Borland C++
code).
This Class is then put into an ACE message class, and sent out to wherever
it
needs to go. There is an ACE gateway which sees this message, grabs it,
and
routes it to an ACE consumer for use (the consumer is associated, in this
instance, with my code). The ACE consumer gets the ACE message, decodes
it
to begin looking at the class (this is Visual C++ 6 code now). From here,
the data needs to get into my application for putting it into Excel (only
option at the moment, other options to follow, including Database, Crystal
reports, etc). I already have the interface that the user sees written in
C#, as well as the Export to Excel code in C#, which is why I would like
to
not need to re-write it all over to C++.

Is re-writing the end-user app in Visual C++ 2003.NET the best way to go?

Nicholas Paldino said:
Andrew,

I'm not sure what you mean by ACE. Also, I don't understand why you
use
C# at all, if you already have a C++ application that is doing the heavy
work (the transformation). Instead of placing in yet another
intermediary
format, why not have the C++ code just write the excel sheet?

If you really want to use managed code, you can do so within C++,
that's
pretty easy, you just have to add a switch (I believe it is /clr).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

message
I thought I would post here, as I am sure someone, somewhere has run
into
this problem, and might have a good solution for me.

I am writing an applicaiton in C# that will accept data and then put it
into
an Excel spreadsheet. Easy, right? Well it is, until you have to get
the
data from another application that is written in Borland C++
PowerBuilder
5.

The situation is that the Borland Code isnt going to get re-written
(too
expensive, couple million lines of code) so we have to develop in
Borland
still to handle some things, and the ACE is being used for ease of
communication between compilers (it is basically platform independent).
Unfortunately, the ACE code is not written in C#, but in C++. So, my
application will have a C++ applicaiton that will be receiveing the
data
form
the Borland Code, and decoding the ACE, and then storing the data
somewhere
(a class, a struct, a file, a stream... wherever is best) and then
sending
this data to my C# code. I am expecting to use one class per distinct
message, and the messages wil continue to grow over time (thousands of
messages is not un-realistic) so I am also trying to find the least
maintenance heavy method to accomplish the task.

How would you recommend I get the data from my unmanaged C++ code and
into
my C# application for quick stuffing into an Excel spreadsheet. Can it
be
done is something close to real-time (maybe with a 1 - 2 second delay)?

Thanks in advance for any ideas, tips, hints, or suggestions.

Andrew S. Giles
 
Back
Top