1

I'm trying to use a *.so library inside a Xamarin Android project, just as used in Java project. I tried putting the library in the path: lib/armeabi/library.so and in the properties of the file:

  • Build action: AndroidNativeLibrary
  • Copy to output: Always

Also, i tried the following code to import a method, as described in:

https://stackoverflow.com/a/15902529/5610132

Code:

[DllImport("libVPOS3515.so")] 
public extern static int Lib_McrRead(byte keyNo, byte mode, byte []track1, byte []track2, byte []track3);

But, how can I use the classes included in the library?

Community
  • 1
  • 1

1 Answers1

0

If your DllImport is:

public extern static int Lib_McrRead(byte keyNo, byte mode, byte[] track1, byte[] track2, byte[] track3);

Something like this:

byte keyNo = {?};
byte mode = {?};
byte[] track1 = {?};
byte[] track2 = {?};
byte[] track3 = {?};
int retValue = Lib_McrRead(keyNo, mode, track1, track2, track3);

(I do not know what what the parameter's value should be of course...)

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • The issue is that I want to use the classes included in the library, not just the methods. – Leonardo De La Cruz Nov 30 '15 at 21:40
  • Not sure you understand what p/invoke interop is, try reading about class marshalling maybe it will help : http://www.mono-project.com/docs/advanced/pinvoke/#class-and-structure-marshaling – SushiHangover Nov 30 '15 at 23:51
  • Also you you are trying to bind c++ classes to use within managed code, then look at CXXI, this transformed to CppSharp. http://tirania.org/blog/archive/2011/Dec-19.html and https://github.com/mono/CppSharp – SushiHangover Nov 30 '15 at 23:58
  • I have the classes from the so implemented in a Java project (but i need to use them in Xamarin), they're used as imports, but I'm not sure what language it is. I thought it was java because of the imports. Anyway, thank you for the links, I will continue researching. – Leonardo De La Cruz Dec 01 '15 at 00:18
  • Binding of Java Libraries would be done via Xamarin's `Managed Callable Wrappers` I would highly recommend going to the native language of the class and not trying to mix multiple levels of marshaling as that is a recipe for failure as debugging would be a nightmare if you could get it to even work correctly... ;-) i.e. http://developer.xamarin.com/guides/android/advanced_topics/java_integration_overview/binding-a-java-library/ – SushiHangover Dec 01 '15 at 00:21