Marshall::Copy and BYTE* and byte[] conversion?

  • Thread starter Thread starter BartMan
  • Start date Start date
B

BartMan

Greetings,

I am trying to copy an unmanaged buffer into a mananged buffer, and trying
to use marshalling, and I am not having any success because it doesn't seem
to complie.

Basically I am using Directshow's sample grabber interface to a filter, and
trying to copy a buffer to a managed buffer will little success.
I get an error that my paramaters do match. I change the parameters, and
still can't seem to get the marshall to compile. I am certain I am doing
something incorrectly, but can't seem to get it to compile.

The code that i am working with is done in C++\Clr using visual studio 2008
on a windows vista machine.

HRESULT STDMETHODCALLTYPE TestDSOnVistaClass::BufferCB( double
SampleTime,BYTE *pBuffer,long BufferLen)
{

// Prep a destination buffer.
cli::array<unsigned char,1>^ destination = gcnew array<unsigned
char>(BufferLen);

// Copy the unmanaged buffer into our destination buffer.
// DOESN'T WORK, won't compile????
System::IntPtr^ source = gcnew System::IntPtr(pBuffer);
System::Runtime::InteropServices::Marshal::Copy(source, destination, 0,
BufferLen);

// Use a 3rd party assembly HERE to process the data in a byte [] format.
// Do not have access to source code but according to developers it is in C#.
// (ie:) doSomething(byte[] data);

return S_OK;
} // end BufferCB()

Thanks in advance for any suggestions!
 
I figured it out, for some reason my intellsense was defaulting to the first
item,
so I scrolled through the intellisense, and selected the correct one.
After that it worked fine. Not sure why my intellesens in C++ was
defaulting to the first one, and not figuring out based on my paramaters.
But it is now working.
 
BartMan said:
Greetings,

I am trying to copy an unmanaged buffer into a mananged buffer, and
trying to use marshalling, and I am not having any success because it
doesn't seem to complie.

Basically I am using Directshow's sample grabber interface to a
filter, and trying to copy a buffer to a managed buffer will little
success.
I get an error that my paramaters do match. I change the parameters,
and still can't seem to get the marshall to compile. I am certain I
am doing something incorrectly, but can't seem to get it to compile.

The code that i am working with is done in C++\Clr using visual
studio 2008 on a windows vista machine.

HRESULT STDMETHODCALLTYPE TestDSOnVistaClass::BufferCB( double
SampleTime,BYTE *pBuffer,long BufferLen)
{

// Prep a destination buffer.
cli::array<unsigned char,1>^ destination = gcnew array<unsigned
char>(BufferLen);

// Copy the unmanaged buffer into our destination buffer.
// DOESN'T WORK, won't compile????
System::IntPtr^ source = gcnew System::IntPtr(pBuffer);

Should be just

System::IntPtr source = pBuffer;

IntPtr is a value type.
System::Runtime::InteropServices::Marshal::Copy(source, destination,
0, BufferLen);

// Use a 3rd party assembly HERE to process the data in a byte []
format. // Do not have access to source code but according to
developers it is in C#. // (ie:) doSomething(byte[] data);

return S_OK;
} // end BufferCB()

Thanks in advance for any suggestions!
 
Back
Top