Change font size
It is currently Tue Jul 28, 2026 1:44 am


Post a new topicPost a reply Page 1 of 1   [ 7 posts ]
Author Message
PostPosted: Mon Apr 03, 2017 1:41 pm 

Joined: Tue Feb 10, 2015 2:28 pm
Posts: 31
Hello all,
I was able to use the animation add-on code with some simple C programs, but wondering if anyone could direct me how to get it working with C#. I know this is more of a general programming question but what I found with marshaling and dll made my head spin. Any direction or place to start for getting automation to work with c# would be greatly appreciated.
Thank you


Top
 Profile  
 
PostPosted: Tue Apr 04, 2017 1:22 am 
iPi Soft

Joined: Wed Jan 11, 2012 6:12 am
Posts: 2355
Location: Moscow, Russia
Hi
Marshaling is not that hard actually and is mostly done automatically. You just need to set proper behavior using attributes.
However, there are some things in our automation library which need accurate handling.
First, the library allocates strings which should be freed by the caller, so output strings need to be passed as IntPtr's and marshaled to managed strings manually.
Second, you probably pass an event callback when connecting. Then you have to ensure that corresponding managed delegate lives until you disconnect so that pointer to it in unmanaged code is valid.
I think I'll write a simple managed wrapper for our API in C# and post it here later today.


Top
 Profile  
 
PostPosted: Tue Apr 04, 2017 5:40 am 

Joined: Tue Feb 10, 2015 2:28 pm
Posts: 31
vmaslov wrote:
Hi
Marshaling is not that hard actually and is mostly done automatically. You just need to set proper behavior using attributes.
However, there are some things in our automation library which need accurate handling.
First, the library allocates strings which should be freed by the caller, so output strings need to be passed as IntPtr's and marshaled to managed strings manually.
Second, you probably pass an event callback when connecting. Then you have to ensure that corresponding managed delegate lives until you disconnect so that pointer to it in unmanaged code is valid.
I think I'll write a simple managed wrapper for our API in C# and post it here later today.


Thank you, that would be great! Until then I will try figuring out marshaling. Thank you for the tips.


Top
 Profile  
 
PostPosted: Tue Apr 04, 2017 9:39 am 
iPi Soft

Joined: Wed Jan 11, 2012 6:12 am
Posts: 2355
Location: Moscow, Russia
Here is the wrapper with little sample code. I took care of those specific things inside so the result looks quite easy to use.
I have made minor changes to DLL generation so that exported functions were easier to consume from .NET. Thus please download the latest version of the library (64-bit DLL is also included with the wrapper).
The code I attach runs on x64 platform. If you need to run on x86 platform, then replace iPiMocapAutomation.dll with 32-bit version. If you need your .NET code to run on AnyCPU platform then you should load the DLL of correct bitness manually before accessing the wrapper. Use the LoadLibrary function from Windows API to load DLL.


Attachments:
File comment: .NET wrapper for iPi Mocap Automation API
iPiAutomationClient.zip [452.5 KiB]
Downloaded 687 times
Top
 Profile  
 
PostPosted: Tue Apr 04, 2017 9:44 am 

Joined: Tue Feb 10, 2015 2:28 pm
Posts: 31
Thank you so much, you are awesome!


Top
 Profile  
 
PostPosted: Wed Apr 05, 2017 9:35 am 

Joined: Tue Feb 10, 2015 2:28 pm
Posts: 31
Just wanted to post if anyone finds this post looking to work with the automation add-on and c#, this wrapper is very powerful used with json.net http://www.newtonsoft.com/json/help/htm ... uction.htm . Thanks again vmaslov


Top
 Profile  
 
PostPosted: Fri Apr 07, 2017 2:11 pm 
iPi Soft

Joined: Wed Jan 11, 2012 6:12 am
Posts: 2355
Location: Moscow, Russia
Just to let know.
We have uploaded a new version of automation client which includes a .NET wrapper (platform-specific binaries for x64 and x86). You may download it to use an "official" .NET library. The API has been changed compared to what I posted here, but these are mostly renamings so migration should be straightforward.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 7 posts ]


Who is online

Users browsing this forum: No registered users and 40 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB® Forum Software © phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net