How to integrate native applications with eclipse? - c#

I have a couple of native applications written in C++ and C#. These are legacy applications that require data sharing between them. Currently, data sharing is through import/export of text file in some proprietary format. We are currently looking at integrating these two applications using eclipse. My questions are:
How can we integrate native applications such as c++ and c# based applications into eclipse?
What kind of data integration methods does eclipse provide for native applications?
Is eclipse the best choice for such use?
Also, it will be very helpful if you can share your experiences about integrating native applications in eclipse.
I am specifically looking at integrating native applications into eclipse just the way we would integrate a eclipse plugin written in Java. For example, what does it take to write a wrapper plugin in Java which will wrap a native tool by using JNI calls that can be integrated into eclipse just as any other eclipse plugin? Is this is a preferred approach for integrating native applications or is it a good idea to rewrite my legacy native application in Java?
I am not looking at using eclipse as a launch pad for my native applications using the "External Tools" configuration.

If you can write a JNI wrapper around your C++/C# applications, then you can use them from an Eclipse plugin.
The simplest approach is to:
repackage your C++/C# applications as DLLs (if they aren't already)
wrap them with a JNI layer
place the DLLs in the root folder of your plugin
call System.LoadLibrary() from a static initializer block in your JNI wrapper class to load required DLLs
You might find the discussion on the Eclipse newsgroup entitled Using DLL in an Eclipse plugin helpful.

There's nothing inherently specific about Eclipse here (that's not to say you can't use it as an IDE). Basically, you should look at P/Invoke, COM Interop, and MSDN's (vast) section on Managed-Unmanaged Interoperability. While you could integrate both sides with Java/SWT, and use it as the middle-man, I don't think that makes much sense.

If you just want to run the apps from inside eclipse use the external tools infrastructure.
If not, please provide more details on the integration that you seek.

Related

DLL project should be of which type for cross platform use

We have one application for both C# .NET and Apple iPad. This application will perform similar functionalities. For this we have one protocol layer which we are thinking to keep as common code. For this we are thinking of creating a C++ dll for the protocol module so that it can be used across both C# and iPad. For creating a C++ dll, I have a basic question:
While creating a dll project, which option should we select? We can create a dll for MFC, Win32, ATL etc. What would be the best option for my requirement?
You should not use MFC as these are the Microsoft Foundation Classes not available on iOS anyway. Probably Win32 would be your best guess - but make sure not to include any non-standard Windows header files if you want to use the DLL in non-Windows environments.
I would recommend to frequently compile your file in both environments. You might also want to take a look at multi-platform libraries like boost if you need advanced functionality.
I recommend looking at Mono for building C# apps on both Windows and iOS.
If you want to target the iPad, you need to build for iOS, not Mac OS.
You cannot build dynamic link libraries for iOS, only static libraries. Note, there are equivalents to DLLs on iOS, but only Apple can build them (or you can build them yourself if your iPad is jailbroken, but this will disqualify your app from the AppStore).
iOS is not related to Windows in any way, so Win32 libraries will not run on iOS. Your generic 'protocol module' (if you mean low-level code that can interface to other devices over TCP/IP or similar) will need to have significant differences depending on which platform it is running upon.

Call C# dll from a Java Application

I have a dll created in c# which does some database operation upon calling. I have to pass few parameters from a Java application to a method in the dll. Any Idea on how to do this.
OR
Any better ideas for calling a method in c# by a java application?
Thanks
Edit : My java application is a standard Dialogue Designer application from AVAYA Platform and I have developed a C# application which works on a SDK for .net only. So i need data to be passed from java application to .net application
IKVM.NET is an implementation of Java for Mono and the Microsoft .NET Framework. It includes the following components:
A Java Virtual Machine implemented in .NET
A .NET implementation of the Java class libraries
Tools that enable Java and .NET interoperability
The third point is maybe what you are looking for.
Project Site here: http://www.ikvm.net/
I looked into this a while back although I enver got far with it as the requirements changed. But I did read that using JNI, Java Native Interface may be able to help you with what you are needing to do.
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html
Hope this helps!

When do I need the Windows SDK and what is .NET for?

I am a student and after taking some introductory programming courses in Java, C, and just finishing up a book on C++, I would like to start developing applications for Windows.
I have done my best to page through google and find the answers I need, but I seem to be at a loss.
When would I need the Windows SDK over just the regular API?
And what is .NET and why would I need it?
What is so special about C# and should I use that over C/C++?
When would I need the Windows SDK over just the regular API?
The SDK includes headers, libraries, tools, etc., that give you access to the API (and to .NET, for that matter). For example, a typical API-based program will start with #include <windows.h> -- but without the SDK, you don't have a copy of Windows.h to include. Likewise, the SDK includes the compilers (the same actual compilers included in the current version of Visual C++), linkers, debuggers, etc., necessary to actually build an API-based program.
And what is .NET and why would I need it?
.NET is a couple of things: a virtual machine that executes code in what Microsoft calls "intermediate language" (IL). It's also a (large) library of code in IL for everything from window management and drawing to communications, system management, etc.
You'd need it primarily if you were writing code in a .NET-based language such as C#, VB.NET, etc.
What is so special about C# and should I use that over C/C++?
C# is (by far) the preferred language for .NET development. Microsoft did develop .NET versions of Visual BASIC, and something at least quite similar to C++, but both tend to lag behind C# (at best).
So, if you're developing code specifically for Windows (especially if it includes a GUI), C# is probably your first choice. Microsoft does a lot more to support it than to support C or C++. That shows up in better support in both libraries and tooling.
The primary argument in favor of using C or C++ would probably be that you're developing primarily for Linux, and then porting the code to Windows. You can still do such development in C# if you want to (e.g., you can run C# and .NET under Linux using Mono), but especially if you're doing the development work under Linux, you lose most of the advantages.
On the other hand, if your code doesn't involve a GUI anyway, you might be able to write portable C or C++, and just compile it under both Windows and Linux. In such a case, using C# could involve extra work, such as having to install Mono to run the code under Linux--not a terribly difficult task, but even a fairly easy installation can be more work than no installation at all.
Windows SDK is a low-level framework for developing applications specifically for Windows. You could use it for your development. However, the APIs are low-level and a little difficult to use and maintain.
Alternatively, you could use .Net. .Net is a framework that includes runtime support for your application. It has many packages, I am sure you will find something useful in .Net. .Net needs a runtime for executation and is not compiled natively to the platform. However, it is easier for software development mostly because the APIs are higher level.
C# is the recommended language for Windows specific programming, specially on .Net. Not that it is the only language, you could also use C/C++, but they are not supported by Microsoft actively. For example, if you use C#, creating a GUI application could just a few mouse clicks. Using C++, you would need to manage your windows instances.
Typically, you would only use C/C++ for Windows programming if you are doing cross-platform programming or some low-level stuffs.

Java to C# Translator

I heard that JNBridge will translate C# code to native Java code.( I haven't tested it).
Is there any tool available in market to translate Java code to native C# ?(or Will JNBridge also translate Java code to C# ?)
Are you talking about a source code converter, or the ability to run Java code in a CLR?
If it's the latter, you might want to look at IKVM:
IKVM.NET is an implementation of Java
for Mono and the Microsoft .NET
Framework. It includes the following
components:
A Java Virtual Machine implemented in
.NET
A .NET implementation of the Java
class libraries
Tools that enable Java
and .NET interoperability
Microsoft's Visual Studio 2005 included a Java to C# conversion tool (the Java Language Conversion Assistant). Although they announced in 2007 it wouldn't be developed further (and it isn't in VS 2008) it is still a supported product until 2015.
I don't think that direct "code translating" could be possible, what with invoking API functions? (like, each technology has it's own collections, etc.). Link that you have given, doesn't seem to be code translator, rather - libraries that allows one to connect components, like embedding java GUI inside WPF app etc.
Also, on the main page of JNBridge, they are writing:
Bridge anything Java to .NET
Bridge anything .NET to Java
So it might a good idea to check someone's site before asking about possibilities of their platform.

Calling C# from native C++, without /clr or COM?

I have a class library written in C#, and I want to call it from a legacy native C++ application. The host application is truly native, compiled on Windows and Linux, and it’s a console application. So how can I make it call the C# class library, assuming using Microsoft .NET on Windows, and Mono on Linux?
I have looked at SWIG and wrapping with COM interfaces on Windows, but is there a standard recognized solution that works cross platform? I.e., that is generic, works with both Microsoft .NET and Mono. A write-once-use-everywhere implementation.
Solutions should expose the full class interfaces from the C# domain to the C++ domain.
Similar questions focus only on the Windows solutions, for example -
Call C# methods from C++ without using COM
If you want to do this cross platform, I would recommend going with a 100% Mono approach.
Mono has a clean Embedding API which works on Linux and Windows.
With .NET 5.0 (the successor of .NET Core) this is now possible to call C# from C++ in a cross-platform way without using Mono. Please see the solution explained in this GitHub issue using DNNE to generate a shared library and GCHandles to access C# objects.
With this you get a shared library that can be used from C or C++. Note that this will give a C-like API (no objects, like when using extern C in C++), in the future there may be tools like SWIG for C++ to overcome this limitation.

Categories