how to communicate between C# (or C++) and JAVA - c#

i am working on a RFID based project in which we should communicate with Gates(RFID tag reader is called a GATE) through our application (and we are using java 2 ee to do this). the problem is the Gates are only shipping with c# and c++ SDK.
what is your solution to communicate between c++ / C# and java? is there any so called convertor that can ease the pain?
and this is the Gates manufacturer website if you need any more info : http://www.marktrace.com/en/default.html
thank you all.

You are searching for the Java native interface which allows you to communicate with other libraries.
You can either call methods from an external DLL and call Java methods from within your C++ code.
You can use jni4net to have a bridge to .NET libraries as well.

Besides using the JNI that the other answers mention, I was writing a similar program for collage and we just wrote a C# client that talked to the library then bridged the gap to java by writing a simple TCP server in C# that the main java app talked to.

JNI - Java Native Interface - You can use it to call C++ code from Java.
http://docs.oracle.com/javase/6/docs/technotes/guides/jni/
Here is a tutorial.

Java Native Interface is what you need. There are also couple of alternatives and specific libs

Related

C# and Delphi integration

Currently we have couple projects that are written in Delphi 6. Because of specific components that use in these projects (components also written in Delphi 6) it is not easy to convert it in newer version.
As I prefer .NET development and our new products are developed in .NET, I would like to develop new functionalities using these technologies. C# will be programming language.
My question is: How to integrate new functionalities developed in C# with current code in Delphi? Is this good idea at all and what can be possible issues? If someone have similar experience it would be to hear advantages and disadvantages.
I heard for integration in way to develop .dll with C# and use it from Delphi code.
TnX in advance!
Nemanja
You can use COM (ActiveX) both ways.
So Yes, you can make a DLL in C# and mark it as COM-visible and import it into Delphi.
But you cannot use simple (not COM) DLLs this way.
My first port of call would probably be looking into WCF (written in C#) and have Delphi talk to it.
The dll is not a bad idea, but I just think putting it in WCF is more scalable + portable.
COM would probably be my choice. However, if for some reason you wanted to avoid COM you could take a look at the very nifty Unmanaged Exports by Robert Giesecke.
Unmanaged Exports is an MSBuild task that essentially allows you to export static functions from your .Net assemblies to be consumed as ordinary native DLL exports.
You may want to check out Hydra from RemObjects. It permits native and managed code to be used in the same application.
http://www.remobjects.com/hydra/default.aspx

Communication between C++ and C# in a metro app

I'm building a metro application where I need to call call a C# lib from C++. Simply calling the C# code wasn't hard. The problem is how I should communicate back from C# to C++. How do I do this in winRT? Is it possible? Because all the examples I've found only have a one way communication.
Ok, it actually was really simple. I could implement a C# interface in my C++ code which I could use as a callback from the C# lib.

Visual Studio 2008 - Sharing Data in C++/C# Multi Project Solution

I have a solution with 2 projects:
a c++ main project
a c# project (display simulator)
Today these 2 apps share data using a loopback TCP client/server connection, but that's not very optimal (timing issues..).
I was wondering if there was a way to access the c# data from the c++ project directly and vice versa? (It seems to be possible with 2 c# projects..)
If it's not possible, what's the best way to implement this with shared memory?
thanks!
Michael
EDIT: thanks for the answers. The 2 projects used to be independant solutions and are both executables - I'm actually trying to merge the 2 into 1 solution / executable.
For info: The c++ app is a PC version of an embedded app - the c# app is a lcd/HMI simulator.
Converting the C++ project to a C++/CLI project might be the easiest way to go. Note however that some code doesn't play well with C++/CLI (we've had problems using libraries that use boost::thread in a managed executable).
You can use COM Interop or Platform Invoke to access native code in C#.
If that's not what you're asking for, please elaborate.
Named Pipes?
For interprocess communication via named pipes you can check out the .NET 3.5 feature
http://msdn.microsoft.com/en-us/library/system.io.pipes.aspx for the C# side. From the C++ side, I assume you know the equivalent :).
There are two ways I know of to get direct access to memory between c++ and c# without the overhead of marshaling/demarshaling and com. If it is required to keep the c++ part of your code native then the only way I know to achieve this is to host the clr from your c++ application. A relatively complicated undertaking. Google "hosting the common language runtime". Then you can load your c# code as an assembly, call into the c# code and provide a common shared memory style interface. Although you will have to write all of the shared memory support yourself as I have found no direct support for shared memory in c#/.net.
The other way is to compile your c++ code with common language runtime support. This is by far easier and will allow you all the power and glory of c++ while allowing access to clr based data types, and the ability to call back and forth between your c++ and c# code. See "Language Features for Targeting the CLR" in your VS2008 documentation. pin_ptr will become your close friend and ally in this process.

C# Interop with C vs Interop with Java: Which is better/easier/faster?

I have an application in C# that currently authenticates to LDAP. We want to extend functionality to support IBM's Tivoli Access Manager, which is comprised of a Policy Server, and an LDAP server (and other modules as well). Unfortunately authenticating with the LDAP server for our customer is not acceptable, thus we must bind with the policy server instead.
The TAM's Policy Server has 2 APIs for authentication, one in Java, and one in C
My question: What is the better language for C# to interop, C or Java?
Keeping in mind: maintainability, and cost of development.
Thanks everyone in Advance.
Seems to me that C is the easier language for C# to inter-operate with, as there's a native interface in .NET to allow "unsafe" access. To communicate with Java, you have to go though JNI to get into Java, or use J#, or otherwise jump through hoops to communicate from C# to Java and back again.
I've not done any C# to Java communication (except across a socket or across Web Services), but I was on a team that used JNI to communicate from Java to COM via C++ code. We ended up having to throw away the JNI solution as too unwieldy. We rewrote the C++ component in C# and used a nailed-up socket for communication between the two components. This worked fabulously.
From this experience, if you are already using C#, then I would use the C API from C#. This is easy to do.
I've had good success with Managed C++/CLI for interfacing with C/C++ in the past, can't speak much on interfacing with java.
Also if you are going for straight C you can export the function calls directly to C#.
I would think that the API you are interfacing is nothing but an API. One front-end is Java, and the other is C, but you probably aren't interacting with Java code, probably just C.
That said, I suppose it would be whichever interface seems simpler. I'm guessing that C is, but if there is some great Java binding software that lets C# access Java libraries easily, it might be better.
Chances are they both link to C code right beneath the API.
I like Eddie's answer, but I would temper it with this observation - it depends on the skill set you ave in house. If you;'ve got a bunch of Java pros, then it makes sense to use Java. If you have a bunch of C-programmers, then the chouice is obvious.
One other comment though : are you sure TAM doesn't do .NET?
You shouldn't need to do any bridge between C# and C or Java. As Cheeso referenced, TAM has had a supported .NET API for a while now -- see here for information.
I am author of jni4net, open source intraprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke.

Consuming a .Net library via COM or direct integration in Java

I have to admit the last time I programmed in Java was a data structures class in high school. So please be kind to this Java noob.
I have spent a good deal of time putting together a C# COM library at work. This library relies heavily on some new .Net technologies (WPF being the big one) so translating it into another language is not really an option. I have tested consuming this library from C++ through the COM interface and that was simple enough. I wanted to also prove that this same library could be used from a Java program.
So the problem that I have run into is that I can not find a free or even inexpensive way to use COM objects from Java. I guess the other solution would be to find a way to directly integrate the library. Does anyone have any input on what might be the best way to accomplish this? I am using Eclipse for my java environment. Below is an example of what my C# codes exposure looks like. Thanks for any direction you can provide.
//Example C# Object Code
[Serializable,
ComVisibleAttribute(true),
Guid("Long Guid String"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(IFooBarStructure)),
ProgID("My Application")]
public class MyFooBarObject
{
public MyFooBarObject(){}
public string DotNetMethod(){ return String.Empty; }
}
You can use JACOB
From the site:
JACOB is a JAVA-COM Bridge that allows you to call COM Automation components from Java. It uses JNI to make native calls into the COM and Win32 libraries.
Sound like the kind of thing you're looking for.
If you have a little bit of money to spend on a commercial product, I recommend that you take a look at Intrinsyc's J-Integra for COM or J-Integra for .NET products. I used their COM product to access a 3rd party ActiveX control (the Bloomberg data access library) from Java code for a project I worked on a few years ago, and it worked very well. They have a reasonable trial / demo policy, and they are quite responsive to support requests.
If you can access your library through C++, you can access it through JNI. JNI is pretty easy to do, just read the guide carefully especially section 8.6 where it talks about the differences between C and C++
The direct Java/.NET integration can be done with OOJNI. Google "Object-Oriented JNI for .NET".
I am author of jni4net, open source intraprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.

Categories

Resources