tags:

views:

112

answers:

2

I want to use in C# these methods:

*      int LibRaw::open_datastream(LibRaw_abstract_datastream *stream)
*      int LibRaw::open_file(const char *rawfile)
*      int LibRaw::open_buffer(void *buffer, size_t bufsize)
*      int LibRaw::unpack(void)
*      int LibRaw::unpack_thumb(void)

that are stored in a libraw.dll. These functions one by one load data from file... I've been reading about P/Invoke but i'm not sure how to invoke them. Can anyone show me an example how to use all of these functions together in C# to load file (raw image stored in folder) or just how to PIvoke one of them.

Thanx!

p.s. maybe this can be useful: http://www.libraw.org/

A: 

Where I work, we've found that the best way to do this is to write wrapping code in C++/CLI. I thought I had a good blog article about this process, but apparently not. I do have two shorter articles, one about how to work with unmanaged static libraries and one on how to wrap libraries (in managed C++ as opposed to C++/CLI). The solution is similar - just that you have to link to a stub library that loads the dll or load the dll yourself and call GetProcAddress to get the routine you're wrapping.

The advantage is that you can call unmanaged code directly from C++/CLI and can control when and how the marshalling happens. The disadvantage is that you're writing in C++ and you have to control when how how marshalling happens.

plinth
+1  A: 

you have to create RCW for C# DLL to make them usable in VC++ see following link might be useful, as it give step by step guide to achieve same :-

http://www.codeproject.com/KB/atl/ComWarpperForDotNet.aspx

thatsalok