I have a piece of hardware in my computer... shared memory. I call it with a .dll that returns a pointer to this shared memory. Once the pointer is returned, the old C++ program writes and reads to a struct mapped to this pointer.
Now I'd like to make a new C# program that does the same thing. Here's the call to the .dll:
[DllImport("scgtapi.dll", EntryPoint = "scgtMapMem")]
public static extern IntPtr scgtMapMem(ref scgtHandle pHandle);
....and use:
IntPtr memPtr = Scramnet.scgtMapMem(ref gtHandle);
if (memPtr.Equals(IntPtr.Zero))
return;
SpecialStruct myStruct = new SpecialStruct();
// Argh, making a copy
myStruct = (SpecialStruct)Marshal.PtrToStructure(memPtr, typeof(SpecialStruct));
Every time I want to "refresh" myStruct I make a call to Marshal.PtrToStructure (??) Don't I have to worry about memPtr being moved around? The real goal is to have myStruct be able to be updated by this hardware outside of my program and yet still reference it (maybe even change a value in it) (thus having a copy == bad).
I hope I'm explaining this correctly... thanks for the help