Robert.S

I have a dll that expects a COM object filled from a call to RtlMoveMemory in kernel32.dll.

The source parameter is specified as an IntPtr and I have a .NET byte[].

Do I pin a GC handle to the array
Or use something like this example

fixed (byte *p=ByteArray) {
IntPtr MyIntPtr= (IntPtr)p;
SomeDllMethod(MyIntPtr);
}

Is there another option

Thank you


Re: Visual C# Language RtlMoveMemory

Peter Ritchie

Something can't expect memory to be filled by a call to RtlMoveMemory, it can only expect the memory it uses to be initialized in a certain way.

You can use RtlMoveMemory without pinning managed memory, but managed objects don't have a "size", so you really have nothing to pass for a length to RtlMoveMemory.

Maybe if you explain what you're trying to do we can over an alternative that doesn't require unsafe code.






Re: Visual C# Language RtlMoveMemory

Robert.S

I have a byte[] containing an image.
I need to fill a managed INSSBuffer for an IWMWriter

The sample In the wrapper project uses Bitmaps
INSSBuffer sampleBuffer = null;
/// bitmapData details
Helpers.CopyMemory(sampleBuffer, bitmapData.Scan0, length);

But I have byte arrays and do not want to create instances of Bitmaps, just fill the INSSBuffer with my binary data.

Thanks




Re: Visual C# Language RtlMoveMemory

Peter Ritchie

It would depend on how you're using the buffer. With interop. you normally don't have to copy memory and you don't have to pin memory, the interop takes care of everything you need.

How are you passing that buffer to the IWMWriter interface






Re: Visual C# Language RtlMoveMemory

Robert.S

The INSSBuffer is passed to the IWMWriter::AllocateSample through the wrapper:

void WriteSample([In] uint dwInputNum,
[In] ulong cnsSampleTime,
[In] uint dwFlags,
[In, MarshalAs(UnmanagedType.Interface)] INSSBuffer pSample);

So as long as I can read the byte[] data into the INSSBuffer it is taken care of.




Re: Visual C# Language RtlMoveMemory

Robert.S

So how can I fill an INSSBUFFER from a byte[]