Because we support multiple platforms (Windows, Solaris, Linux, Mac), our Decode SDK is written in C++. Some years ago, our C++ APIs used to regularly lead to the question, “do you support Java?”. The answer was always sorry, no, we’re not a Java shop and we don’t have any Java bindings… But we’ve always provided a relatively simple C API which we claimed could be wrapped using JNI, and for the most part that made people happy.
For the past year or so, though, all the Java requests seem to have disappeared, only to be replaced by the question, “do you support .NET?” This usually means “do you have any C# bindings?”, although we do get the occasional VB.NET request. Our response has been sorry, no, we’re not a C# shop and we don’t have any .NET bindings… But, again, we’ve told people that “it ought to be fairly easy to call out to our C API using P/Invoke, .NET’s Interop functionality”.
Well, recently some of the engineers here at LizardTech HQ have started programming in C# for reals, and so now we actually have just enough in-house expertise on the question to be able to provide some additional help on this one. While the current DSDK release doesn’t provide any C# bindings, we have put together a very simple example app that shows how to use Interop to access the C API.
The code is, at heart, remarkably simple. First, you declare your C functions so they can be accessed from within your C# class, like so:
[DllImport("lti_dsdk_cdll.dll")]
static extern int ltic_openMrSIDImageFile(out
IntPtr image, string fileName);
[DllImport("lti_dsdk_cdll.dll")]
static extern uint ltic_getWidth(IntPtr image);
Then, you close your eyes, tap your ruby slippers together three times, and innocently call the functions just like they were real functions:
// this is essentially our void* pointer
IntPtr image = IntPtr.Zero;
string infile = "...";
sts = ltic_openMrSIDImageFile(out image, infile);
...
uint width = ltic_getWidth(image);
...
You can download the full example from here.
Yes, we know, it’d be nice to provide interop support for the C++ classes so as to give access to the whole SDK… but quite frankly, we’re not sure the market demand is really there yet. At the very least, though, we’ll try to include interop support for the C API in the next release of the SDK.
Keep those cards and letters coming.
-mpg