Linking liberary with CLR

Jef Driesen jef at libdivecomputer.org
Wed Mar 1 10:29:03 PST 2017


On 28-02-17 22:21, Vincent Hagen wrote:
> For a small project of mine I tried to link your library to a C# project.
> This failed due to the fact that your library is unmanaged, so I tried creating
> a C++/CLR  wrapper to do this, but I kept failing. Now isn't C++/CLR really in
> my comfort zone and even though I created a .lib file out of your .def file the
> compiler didn't seem to pick up the .dll itself and I have no clue how to do it.
>
> Does anyone have any experience in linking C++/CLR to this libdivecomputer? Or
> even better, with C#?

You can certainly use libdivecomputer from C#. But instead of trying to link the 
C code into your application, you can simply call the native functions from the 
library (build as dll) using P/Invoke.

I've attached some minimal example code. I never had time to finish it, but I 
think there should be enough to get you started.

Jef
-------------- next part --------------
A non-text attachment was scrubbed...
Name: common.cs
Type: text/x-csharp
Size: 400 bytes
Desc: not available
URL: <http://libdivecomputer.org/pipermail/devel/attachments/20170301/4b7b0e02/attachment-0006.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: context.cs
Type: text/x-csharp
Size: 1689 bytes
Desc: not available
URL: <http://libdivecomputer.org/pipermail/devel/attachments/20170301/4b7b0e02/attachment-0007.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: descriptor.cs
Type: text/x-csharp
Size: 2564 bytes
Desc: not available
URL: <http://libdivecomputer.org/pipermail/devel/attachments/20170301/4b7b0e02/attachment-0008.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: device.cs
Type: text/x-csharp
Size: 5173 bytes
Desc: not available
URL: <http://libdivecomputer.org/pipermail/devel/attachments/20170301/4b7b0e02/attachment-0009.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: parser.cs
Type: text/x-csharp
Size: 6294 bytes
Desc: not available
URL: <http://libdivecomputer.org/pipermail/devel/attachments/20170301/4b7b0e02/attachment-0010.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.cs
Type: text/x-csharp
Size: 6263 bytes
Desc: not available
URL: <http://libdivecomputer.org/pipermail/devel/attachments/20170301/4b7b0e02/attachment-0011.bin>


More information about the devel mailing list