| ipisoft.com https://forum.ipisoft.com/ |
|
| Ipi Automation Add-on with C# https://forum.ipisoft.com/viewtopic.php?f=2&t=9745 |
Page 1 of 1 |
| Author: | TTrue [ Mon Apr 03, 2017 1:41 pm ] |
| Post subject: | Ipi Automation Add-on with C# |
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 |
|
| Author: | vmaslov [ Tue Apr 04, 2017 1:22 am ] |
| Post subject: | Re: Ipi Automation Add-on with C# |
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. |
|
| Author: | TTrue [ Tue Apr 04, 2017 5:40 am ] |
| Post subject: | Re: Ipi Automation Add-on with C# |
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. |
|
| Author: | vmaslov [ Tue Apr 04, 2017 9:39 am ] | ||
| Post subject: | Re: Ipi Automation Add-on with C# | ||
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.
|
|||
| Author: | TTrue [ Tue Apr 04, 2017 9:44 am ] |
| Post subject: | Re: Ipi Automation Add-on with C# |
Thank you so much, you are awesome! |
|
| Author: | TTrue [ Wed Apr 05, 2017 9:35 am ] |
| Post subject: | Re: Ipi Automation Add-on with C# |
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 |
|
| Author: | vmaslov [ Fri Apr 07, 2017 2:11 pm ] |
| Post subject: | Re: Ipi Automation Add-on with C# |
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. |
|
| Page 1 of 1 | All times are UTC - 8 hours [ DST ] |
| Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |
|