Re: [ctypes-users] Special use case for ctypes
Brought to you by:
theller
From: eryk s. <er...@gm...> - 2017-05-05 04:45:50
|
On Thu, May 4, 2017 at 9:37 PM, Zak Smolen <zak...@gm...> wrote: > > 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. A DLL can use a shared memory section (i.e. a #pragma data_seg with the shared attribute) for data that's shared across all processes, but otherwise its global data is private to each process. Use VMMap [1] to look at how pages in the .data section are mapped in your DLL. [1]: https://technet.microsoft.com/en-us/sysinternals/vmmap.aspx > Also, the CDLL class is able to take a handle pointer to use instead of > calling LoadLibrary. An HMODULE 'handle' is a pointer to the base address where the DLL is mapped in the current process. It won't necessarily load at the same address in every process. Even if it's mapped at the same address, its global .data will be mapped to private pages. > Anyone have any ideas that may help with this task? You could look into embedding Python into you .NET process. I thought Python for .NET did that, but I've never used it and rarely touch any of the .NET universe. Alternatively, if you're the author of the DLL you could put the global variables that need to be shared in a .shared section. But there are restrictions on what can be shared. For example, each process has its own address space, so sharing pointers should be avoided. Also, most handles can't be shared (e.g. kernel handles such as File handles are privately defined in the handle table of each process). |