By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 2,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

legacy code interface: Java JNI vs .NET interoperability

P: n/a
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 Interoperability" 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
Share this Question
Share on Google+
3 Replies


P: n/a
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**************@exisconsulting.com

"Sai Kit Tong" <sk****@mmm.com> wrote in message
news:%2****************@TK2MSFTNGP10.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 Interoperability" 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

P: n/a
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**************@exisconsulting.com> wrote
in message news:Of****************@tk2msftngp13.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**************@exisconsulting.com

"Sai Kit Tong" <sk****@mmm.com> wrote in message
news:%2****************@TK2MSFTNGP10.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 Interoperability" 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

P: n/a

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 interoperability
| 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.public.dotnet.languages.csharp
| NNTP-Posting-Host: 130.99.229.109
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA06.phx.gbl!TK2MSFTNGXA0
5.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gb l
| Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.csharp:184222
| X-Tomcat-NG: microsoft.public.dotnet.languages.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**************@exisconsulting.com>
wrote
| in message news:Of****************@tk2msftngp13.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**************@exisconsulting.com
| >
| > "Sai Kit Tong" <sk****@mmm.com> wrote in message
| > news:%2****************@TK2MSFTNGP10.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 Interoperability"
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 discussion thread is closed

Replies have been disabled for this discussion.