Re: Special use case for ctypes
Nicolas Pinault <[email protected]> Tue, 9 May 2017 10:03:35 +0200
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format. --===============2155575895449990069== Content-Type: multipart/alternative; boundary="------------09656D746B431FF665343ADB" This is a multi-part message in MIME format. --------------09656D746B431FF665343ADB Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit One way to do what you want is to create a process linked with your library. This process is the single access point to your C library. This process communicates with other processes (Pyhton and C#) through sockets, pipes or anything else. Le 04/05/2017 à 23:37, Zak Smolen a écrit : > Hi, > > I am trying to do something odd, and I was hoping someone may have > some ideas/guidance. > > My application has a C later, accessed by C# layers. I also have a > python wrapper for that C layer written using ctypes. I would like to > have the C# call python scripts which would then, using my library, do > things to the /same instance /of the C DLL as the C# is using. > > I know this is a complex task, but I feel like it should be possible. > After searching around the source code a bit I found a few things. On > my windows machine (windows-only is fine initially) it is using the > LoadLibrary function from kernel32. Also, the CDLL class is able to > take a handle pointer to use instead of calling LoadLibrary. > > So, I wrote this little wrapper function and I was able to pass in the > handle that the C# is using for the DLL so that the python is using > the same handle. That didn't seem to cut it. Anyone have any ideas > that may help with this task? > > Also, before you suggest it, I know about things like IronPython and > Python for .NET. The issues there are twofold: first, they are > restricted and don't have all libs, especially IronPython. Second, if > I want to use the python library, it still gets a different instance. > > Thanks, > Zak > > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > > > _______________________________________________ > ctypes-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/ctypes-users -- *Nicolas PINAULT R&D electronics engineer *** [email protected] <mailto:[email protected]> *AATON-Digital* 38000 Grenoble - France Tel +33 4 7642 9550 http://www.aaton.com http://www.transvideo.eu French Technologies for Film and Digital Cinematography Follow us on Twitter @Aaton_Digital @Transvideo_HD Like us on Facebook https://www.facebook.com/AatonDigital --------------09656D746B431FF665343ADB Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: 8bit <html> <head> <meta content="text/html; charset=windows-1252" http-equiv="Content-Type"> </head> <body bgcolor="#FFFFFF" text="#000000"> <div class="moz-cite-prefix">One way to do what you want is to create a process linked with your library. This process is the single access point to your C library. This process communicates with other processes (Pyhton and C#) through sockets, pipes or anything else.<br> <br> <br> Le 04/05/2017 à 23:37, Zak Smolen a écrit :<br> </div> <blockquote cite="mid:CAODUn54zKuj-+yzghC_noZzTT8VeDSGQzJQt5Yu+STMDMc=X3A@mail.gmail.com" type="cite"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <div dir="ltr">Hi, <div><br> </div> <div>I am trying to do something odd, and I was hoping someone may have some ideas/guidance.<br> <br> My application has a C later, accessed by C# layers. I also have a python wrapper for that C layer written using ctypes. I would like to have the C# call python scripts which would then, using my library, do things to the <i>same instance </i>of the C DLL as the C# is using.</div> <div><br> </div> <div>I know this is a complex task, but I feel like it should be possible. After searching around the source code a bit I found a few things. On my windows machine (windows-only is fine initially) it is using the LoadLibrary function from kernel32. Also, the CDLL class is able to take a handle pointer to use instead of calling LoadLibrary.</div> <div><br> </div> <div>So, I wrote this little wrapper function and I was able to pass in the handle that the C# is using for the DLL so that the python is using the same handle. That didn't seem to cut it. Anyone have any ideas that may help with this task?</div> <div><br> </div> <div>Also, before you suggest it, I know about things like IronPython and Python for .NET. The issues there are twofold: first, they are restricted and don't have all libs, especially IronPython. Second, if I want to use the python library, it still gets a different instance.</div> <div><br> </div> <div>Thanks,</div> <div>Zak</div> </div> <br> <fieldset class="mimeAttachmentHeader"></fieldset> <br> <pre wrap="">------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! <a class="moz-txt-link-freetext" href="http://sdm.link/slashdot">http://sdm.link/slashdot</a></pre> <br> <fieldset class="mimeAttachmentHeader"></fieldset> <br> <pre wrap="">_______________________________________________ ctypes-users mailing list <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a> <a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/ctypes-users">https://lists.sourceforge.net/lists/listinfo/ctypes-users</a> </pre> </blockquote> <br> <br> <div class="moz-signature">-- <br> <font face="arial" size="1"> <font color="0096ff"> <b> Nicolas PINAULT<br> R&D electronics engineer<br> </b></font><b> </b> <a href="mailto:[email protected]">[email protected]</a><br> <br> <font color="0096ff"> <b>AATON-Digital</b><br> </font> 38000 Grenoble - France<br> Tel +33 4 7642 9550<br> <br> <a href="http://www.aaton.com">http://www.aaton.com</a><br> <a href="http://www.transvideo.eu">http://www.transvideo.eu</a><br> French Technologies for Film and Digital Cinematography<br> <br> Follow us on Twitter<br> @Aaton_Digital<br> @Transvideo_HD<br> <br> Like us on Facebook<br> <a href="https://www.facebook.com/AatonDigital">https://www.facebook.com/AatonDigital</a><br> <br> </font></div> </body> </html> --------------09656D746B431FF665343ADB-- --===============2155575895449990069== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot --===============2155575895449990069== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ctypes-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ctypes-users --===============2155575895449990069==--