I need to pass a byte array into a C++ com object from C#. C++ will then fill the buffer for C# to read.
c++ function definition
STDMETHODIMP CSampleGrabber::GetBuffer(byte* bd)
{
int p=0;
while (p< nBufSize) {
bd[p]=pLocalBuf[p];
p++;
}
c# code :
byte[] byTemp = new byte[nBufSize];
igb.GetBuffer(ref byTemp);
This crashes the program with no exception. Please can someone help. Thanks
SOLVED:
with
byte[] byTemp = new byte[nBufSize];
GCHandle h = GCHandle.Alloc(byTemp, GCHandleType.Pinned);
igb.GetBuffer(h.AddrOfPinnedObject());
Thanks
GetBuffermethod?byTemp = new byte[nBufSize]; GCHandle h = GCHandle.Alloc(byTemp, GCHandleType.Pinned); igb.GetBuffer(h.AddrOfPinnedObject());