Hey guys I was wondering if anyone has had experience with using Shared Named Memory for IPC. I'm a little stuck with writing to my shared memory segment between my inject C++ DLL and a C# Controller.
Lets say in my C# Controller I have a managed data type of float and I want to write that data structure to my shared memory. So I would think I would use the Marshal class to allocate some unmanaged memory. Followed by obtaining a pointer to the newly created memory and using PInvoke to CopyMemory the data structure to my shared memory.
Unfortunately I have hit a hurdle and think I am going about this the wrong way (ie Using the concept of shared memory incorrectly). Am I suppose to be using serialisation in order to store the data types?
Another thing I'd like some reassurance on how others use IPC to communicate from their controller to their DLL. Are they simply writing flags from the controller to the DLL to lets say invoke the CTM function? Or have you got some form of interrupt voodoo happening that your DLL can pick up?
If someone can nudge me in the right direction that would be much appreciated. Any insight provided would be awesome. I feel like I am just bashing my head against a brick wall right now.
P.S. I am currently am able to read and write Strings to my Shared Named Memory right now. Just it seems to fail if I attempt to write bytes to my memory.
Code://String to write to managed memory string s = "Meow" IntPtr ptr = Marshal.StringToHGlobalUni(s); //pBuf is the handle to the shared named memory SnausWin32APIs.CopyMemory(pBuf, ptr, 8); //Free ptr Marshal.FreeHGlobal(ptr);