473,732 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

legacy code interface: Java JNI vs .NET interoperabilit y

Hi,

I am developing a new application running on Windows platform that needs to
interface with existing legacy code - written in basic C / C++. I am trying
to evaluate Java vs C# implementations . Originally, I have the impression
that C# should be a clear winner.

I started with Java and using the guideline from the book "Java Native
Interface". Though complex, the book provide details of the practical
implementation and potential pitfalls for poor implementation. Particularly,
it provides a clear picture on life cycle managment, garbage collection,
exception handling (responsibility ) and retaining of object oriented
implementation (one-to-one mapping). However, when I switched my focus on
C#, I had difficult in finding good literature and examples for handling
those issues. I checked Chapter 1 of "COM and .NET Interoperabilit y" and
Chapter 15/16 of "Essential Guide to Managed Extensions for C++". Hence,
that makes me lean on the Java implementation that the C# implementation -
based on the fact that I know what I will get in details. Did I miss any
information critical? Could anyone point me to better article in this
particular aspect?

Thanks in advance.

Nov 15 '05 #1
3 4020
Sai,

Personally, I feel that the interop picture in .NET is way better than
in Java (on the windows platform, that is). Is all of your code in C/C++?
Did you export all of your code through functions, or are they in libraries
of C++ objects? If they are all in objects, then you will have to create
some managed wrappers, in which case, the MSDN documentation is your best
bet. There are a number of articles in there on how to wrap your native C++
objects in managed code (the easiest being to aggregate the code, using the
"__nogc" type declaration).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Sai Kit Tong" <sk****@mmm.com > wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi,

I am developing a new application running on Windows platform that needs to interface with existing legacy code - written in basic C / C++. I am trying to evaluate Java vs C# implementations . Originally, I have the impression
that C# should be a clear winner.

I started with Java and using the guideline from the book "Java Native
Interface". Though complex, the book provide details of the practical
implementation and potential pitfalls for poor implementation. Particularly, it provides a clear picture on life cycle managment, garbage collection,
exception handling (responsibility ) and retaining of object oriented
implementation (one-to-one mapping). However, when I switched my focus on
C#, I had difficult in finding good literature and examples for handling
those issues. I checked Chapter 1 of "COM and .NET Interoperabilit y" and
Chapter 15/16 of "Essential Guide to Managed Extensions for C++". Hence,
that makes me lean on the Java implementation that the C# implementation -
based on the fact that I know what I will get in details. Did I miss any
information critical? Could anyone point me to better article in this
particular aspect?

Thanks in advance.

Nov 15 '05 #2
Thanks for the reply. I went back to MSDN and there is a chapter on Managed
C++ Migration Guide talking about C++ Wrapper. However, I am confused by
that article. The description in that article seems to focusing on wrapping
around C++ class that you already have "SOURCE CODE". I am looking into
interfacing with legacy C/C++ code without the source - I only have the
class header or the function signature, and I couldn't recompile the legacy
code/library. I looked through the PInvoke services prior to submitting my
first mail. As I mentioned, I couldn't find article on the PInvoke service
addressing life cycle managment, garbage collection, exception handling
(native/managed code responsibility) and retaining of object oriented
implementation (one-to-one mapping) and threading.

Might be I misunderstand the actual articles that you are referring. Could
you get me the direct links to those articles. Thanks in advance again.

"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com> wrote
in message news:Of******** ********@tk2msf tngp13.phx.gbl. ..
Sai,

Personally, I feel that the interop picture in .NET is way better than
in Java (on the windows platform, that is). Is all of your code in C/C++?
Did you export all of your code through functions, or are they in libraries of C++ objects? If they are all in objects, then you will have to create
some managed wrappers, in which case, the MSDN documentation is your best
bet. There are a number of articles in there on how to wrap your native C++ objects in managed code (the easiest being to aggregate the code, using the "__nogc" type declaration).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Sai Kit Tong" <sk****@mmm.com > wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi,

I am developing a new application running on Windows platform that needs

to
interface with existing legacy code - written in basic C / C++. I am

trying
to evaluate Java vs C# implementations . Originally, I have the impression that C# should be a clear winner.

I started with Java and using the guideline from the book "Java Native
Interface". Though complex, the book provide details of the practical
implementation and potential pitfalls for poor implementation.

Particularly,
it provides a clear picture on life cycle managment, garbage collection,
exception handling (responsibility ) and retaining of object oriented
implementation (one-to-one mapping). However, when I switched my focus on C#, I had difficult in finding good literature and examples for handling
those issues. I checked Chapter 1 of "COM and .NET Interoperabilit y" and
Chapter 15/16 of "Essential Guide to Managed Extensions for C++". Hence, that makes me lean on the Java implementation that the C# implementation - based on the fact that I know what I will get in details. Did I miss any
information critical? Could anyone point me to better article in this
particular aspect?

Thanks in advance.


Nov 15 '05 #3

Hi Sai,

Yes, Wrapper is based on source code level.
I think you should use the .Net interop to consume the unmanaged .dll.
If you dlls are component, you can refer to the COM interop.

There are many articles referring to the interop in MSDN.
You can search interop keyword in MSDN.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Sai Kit Tong" <sk****@mmm.com >
| References: <#S************ **@TK2MSFTNGP10 .phx.gbl>
<Of************ **@tk2msftngp13 .phx.gbl>
| Subject: Re: legacy code interface: Java JNI vs .NET interoperabilit y
| Date: Mon, 15 Sep 2003 09:23:04 -0500
| Lines: 76
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <O3************ **@TK2MSFTNGP12 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: 130.99.229.109
| Path:
cpmsftngxa07.ph x.gbl!cpmsftngx a10.phx.gbl!TK2 MSFTNGXA06.phx. gbl!TK2MSFTNGXA 0
5.phx.gbl!TK2MS FTNGP08.phx.gbl !TK2MSFTNGP12.p hx.gbl
| Xref: cpmsftngxa07.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1842 22
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
|
| Thanks for the reply. I went back to MSDN and there is a chapter on
Managed
| C++ Migration Guide talking about C++ Wrapper. However, I am confused by
| that article. The description in that article seems to focusing on
wrapping
| around C++ class that you already have "SOURCE CODE". I am looking into
| interfacing with legacy C/C++ code without the source - I only have the
| class header or the function signature, and I couldn't recompile the
legacy
| code/library. I looked through the PInvoke services prior to submitting my
| first mail. As I mentioned, I couldn't find article on the PInvoke service
| addressing life cycle managment, garbage collection, exception handling
| (native/managed code responsibility) and retaining of object oriented
| implementation (one-to-one mapping) and threading.
|
| Might be I misunderstand the actual articles that you are referring. Could
| you get me the direct links to those articles. Thanks in advance again.
|
| "Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com>
wrote
| in message news:Of******** ********@tk2msf tngp13.phx.gbl. ..
| > Sai,
| >
| > Personally, I feel that the interop picture in .NET is way better
than
| > in Java (on the windows platform, that is). Is all of your code in
C/C++?
| > Did you export all of your code through functions, or are they in
| libraries
| > of C++ objects? If they are all in objects, then you will have to
create
| > some managed wrappers, in which case, the MSDN documentation is your
best
| > bet. There are a number of articles in there on how to wrap your native
| C++
| > objects in managed code (the easiest being to aggregate the code, using
| the
| > "__nogc" type declaration).
| >
| > Hope this helps.
| >
| >
| > --
| > - Nicholas Paldino [.NET/C# MVP]
| > - ni************* *@exisconsultin g.com
| >
| > "Sai Kit Tong" <sk****@mmm.com > wrote in message
| > news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
| > > Hi,
| > >
| > > I am developing a new application running on Windows platform that
needs
| > to
| > > interface with existing legacy code - written in basic C / C++. I am
| > trying
| > > to evaluate Java vs C# implementations . Originally, I have the
| impression
| > > that C# should be a clear winner.
| > >
| > > I started with Java and using the guideline from the book "Java Native
| > > Interface". Though complex, the book provide details of the practical
| > > implementation and potential pitfalls for poor implementation.
| > Particularly,
| > > it provides a clear picture on life cycle managment, garbage
collection,
| > > exception handling (responsibility ) and retaining of object oriented
| > > implementation (one-to-one mapping). However, when I switched my focus
| on
| > > C#, I had difficult in finding good literature and examples for
handling
| > > those issues. I checked Chapter 1 of "COM and .NET Interoperabilit y"
and
| > > Chapter 15/16 of "Essential Guide to Managed Extensions for C++".
| Hence,
| > > that makes me lean on the Java implementation that the C#
| implementation -
| > > based on the fact that I know what I will get in details. Did I miss
any
| > > information critical? Could anyone point me to better article in this
| > > particular aspect?
| > >
| > > Thanks in advance.
| > >
| > >
| > >
| >
| >
|
|
|

Nov 15 '05 #4

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

Similar topics

3
1765
by: masood.iqbal | last post by:
In this day and age, you never say no to any work that is thrown at you ---- so when I was offered this short-term contract to convert legacy C code to C++, I did not say no. Personally I believed that it was a somewhat futile exercise since one of the main requirements was for the existing API (a functional interface written in C) to remain the same. I would have much rathered that the mandate be ab-initio, but that was not the case...
3
2375
by: Sai Kit Tong | last post by:
I posted for help on legacy code interface 2 days ago. Probably I didn't make it clear in my original mail. I got a couple of answers but none of them address my issues directly (See attached response). My first reply directed me to source code migration but I didn't have the source code. The second reply mentioned about .NET interoperability (PInvoke I think) but I MENTIONED THAT I COULDN'T FIND ANY DOCUMENTATION FROM MSDN LIBRARY BASED ON...
1
2096
by: Sai Kit Tong | last post by:
I have to interface managed application with my legacy dll. I have employed the wrapper approach but I have to deal with the asynchronous callback from the legacy dll, which likely goes through a thread other than the initial calling thread. I got the idea from MSDN and other responses from this group by using the delegate. However, for garabage collection issue, I need to pin the delegate. Since my callback is asynchronous, I have been...
6
12689
by: Jim | last post by:
Can you call exisiting Java classes from C#?
3
2118
by: Max Christian | last post by:
I'm writing a mixed-mode C++ DLL which is used by an old C++ application that I don't have the source code to. I'm amazed by the ease of interoperability, but the one problem I'm having is debugging the DLL, as the C++ app crashes if loaded into the debugger. If I could just get the line number on which an exception occurred that would be enough to fix most bugs. At the moment I use exception.ToString() and get a stack trace but it's...
4
3353
by: jos | last post by:
Hi There, What would be suitable options to exchange data between a Dot net program and a java program? Thanks Jyotsna Sharan
7
4983
by: Christian Wilhelm | last post by:
Hi! I'm trying to call a Java WebService out of a .net Client. There are two Methods, one Method requires one Parameter of type Parameter, the other Method requires one Parameter of type Parameter. I can call the first Method without Problems, the Parameter can be deserialized by the WebService. But if I want to call the second Method and give it an Array of Parameters, then the following exception is thrown by the WebService:...
11
1455
by: jason | last post by:
we have developed a .NET class library that defines a family of reusable business objects. the class library is developed in C#, and works quite well. one problem, however, is that as more and more applications are being developed to consume this class library, we are running into deployment and version controll issues. i recall a lot of this kind of thing being solved with distributed application models, such as the EJB...
7
1821
by: Ben Finney | last post by:
Howdy all, I'm working on a web application that is starting to gain a lot of back-end code written in Python. However, all the current interface code is written in legacy PHP. I'd like to slowly introduce new features as Python WSGI programs. Is it possible to write a Python WSGI program that talks to a PHP program as its "back end"? Where can I find out how to do this, preferably with examples?
0
8946
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
8774
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
9307
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
9235
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
8186
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...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
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...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.