[ACCEPTED]-Access memory address in c#-activex
You can use Marshal.Copy to copy the data from native 3 memory into an managed array. This way you 2 can then use the data in managed code without 1 using unsafe code.
I highly suggest you use an IntPtr and Marshal.Copy. Here 8 is some code to get you started. memAddr 7 is the memory address you are given, and 6 bufSize is the size.
IntPtr bufPtr = new IntPtr(memAddr);
byte[] data = new byte[bufSize];
Marshal.Copy(bufPtr, data, 0, bufSize);
This doesn't require 5 you to use unsafe code which requires the 4 the /unsafe compiler option and is not verifiable 3 by the CLR.
If you need an array of something 2 other than bytes, just change the second 1 line. Marshal.Copy has a bunch of overloads.
I think you are looking for the IntPtr
type. This 3 type (when used within an unsafe
block) will allow 2 you to use the memory handle from the ActiveX 1 component.
C# can use pointers. Just use the 'unsafe' keyword 7 in front of your class, block, method, or 6 member variable (not local variables). If 5 a class is marked unsafe all member variables 4 are unsafe as well.
unsafe class Foo
{
}
unsafe int FooMethod
{
}
Then you can use pointers 3 with * and & just like C.
I don't know 2 about ActiveX Components in the same address 1 space.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.