Creating a Managed Wrapper for C API

Crank Storyboard Designer samples and code snippets.

Moderator: jamiev

Creating a Managed Wrapper for C API

Postby rmgillmore » Thu Jan 08, 2015 2:48 pm

Our customer has approached us about creating a way to make calls to the greio library from LabView. LabView can call Managed DLLs, but not Unmanaged LIB.

Has anyone done that? It is perhaps a task that is not for the faint of heart.

Thank you.

>Mike
rmgillmore
 
Posts: 3
Joined: Thu Jan 08, 2015 2:27 pm

Re: Creating a Managed Wrapper for C API

Postby rmgillmore » Thu Jan 08, 2015 4:29 pm

I have figured out how to bridge the divide between the unmanaged (the C++ wrapper on the GRE I/O library) and the managed (.NET wrapper). Now it seems that the symbols in the library do not have a leading underscore. For instance:

The Microsoft (R) COFF/PE Dumper reports the public symbols as:
1 gre_io_add_mdata
9 gre_io_close
A gre_io_free_buffer
9 gre_io_grow_buffer
9 gre_io_max_message
9 gre_io_open
9 gre_io_receive
9 gre_io_send
1 gre_io_send_mdata
A gre_io_serialize
A gre_io_size_buffer
A gre_io_unserialize
A gre_io_zero_buffer

Note the absence of the leading underscore. This is not what I would expect of a C API.

>Mike
rmgillmore
 
Posts: 3
Joined: Thu Jan 08, 2015 2:27 pm

Re: Creating a Managed Wrapper for C API

Postby thomas » Thu Jan 08, 2015 8:46 pm

Mike,

It should be relatively straightforward to wrap the library we provide into any form you need. We have done
this ourselves to create a C# module that can be used with C# applications (I have attached it here).

I am not sure I understand your comment regarding the library symbols. While C/C++ standard libraries
may choose to use an _, these are generally reserved for use by the compiler and system namespaces.
There should be no issue for you to use the symbols that are exported.

Thomas
Attachments
SBCSharp.txt
C# example linkage
(4.21 KiB) Downloaded 556 times
thomas
 
Posts: 133
Joined: Mon Nov 02, 2009 4:32 pm
Location: Ottawa

Re: Creating a Managed Wrapper for C API

Postby rmgillmore » Fri Jan 09, 2015 2:16 pm

CSharpLib.150109.cs.txt
(2.77 KiB) Downloaded 584 times


I created the attached code to have it fit the interface between our application and the managed DLL that I created. I am getting an exception (screen shot attached, also).
CSharpLib.Exception.jpg
CSharpLib.Exception.jpg (58.6 KiB) Viewed 12729 times


Does anyone have any ideas?

>Mike
rmgillmore
 
Posts: 3
Joined: Thu Jan 08, 2015 2:27 pm


Return to Samples

Who is online

Users browsing this forum: No registered users and 1 guest