如何从托管c+;封送字节数组+;到c# < >我想使用C++托管项目中的.NET图形功能。我想从内存中的C++字节数组创建Wistop.DavaIn图像(基于内存流)。p>

如何从托管c+;封送字节数组+;到c# < >我想使用C++托管项目中的.NET图形功能。我想从内存中的C++字节数组创建Wistop.DavaIn图像(基于内存流)。p>,c++,marshalling,managed-c++,C++,Marshalling,Managed C++,如何使这段代码正常工作: System::IO::Stream^ ms = gcnew System::IO::MemoryStream(); BYTE buf[1024 * 8]; // C++ int size; // C++ ... ms->Write(&buf, 0, size) 提前谢谢你 您可以这样做: int size = 1024; BYTE buf[1024]; // unmanaged buffer System::IntPtr intPtr = S

如何使这段代码正常工作:

System::IO::Stream^ ms = gcnew System::IO::MemoryStream();
BYTE buf[1024 * 8];  // C++
int size;  // C++
...
ms->Write(&buf, 0, size) 

提前谢谢你

您可以这样做:

int size = 1024;

BYTE buf[1024];

// unmanaged buffer
System::IntPtr intPtr = System::IntPtr( buf );

// managed buffer 
array<unsigned char>^ managedBuf = gcnew array<unsigned char>(size);

{
    // write things to buf[]
}

// copy unmanaged buffer to managed buffer
Marshal::Copy( intPtr, managedBuf, 0, size );

System::IO::Stream^ ms = gcnew System::IO::MemoryStream();

ms->Write( managedBuf, 0, size);
int size=1024;
字节buf[1024];
//非托管缓冲区
System::IntPtr IntPtr=System::IntPtr(buf);
//托管缓冲区
数组^managedBuf=gcnew数组(大小);
{
//写东西给buf[]
}
//将非托管缓冲区复制到托管缓冲区
封送:复制(intPtr,managedBuf,0,size);
System::IO::Stream ^ms=gcnew System::IO::MemoryStream();
ms->Write(managedBuf,0,大小);

您可以这样做:

int size = 1024;

BYTE buf[1024];

// unmanaged buffer
System::IntPtr intPtr = System::IntPtr( buf );

// managed buffer 
array<unsigned char>^ managedBuf = gcnew array<unsigned char>(size);

{
    // write things to buf[]
}

// copy unmanaged buffer to managed buffer
Marshal::Copy( intPtr, managedBuf, 0, size );

System::IO::Stream^ ms = gcnew System::IO::MemoryStream();

ms->Write( managedBuf, 0, size);
int size=1024;
字节buf[1024];
//非托管缓冲区
System::IntPtr IntPtr=System::IntPtr(buf);
//托管缓冲区
数组^managedBuf=gcnew数组(大小);
{
//写东西给buf[]
}
//将非托管缓冲区复制到托管缓冲区
封送:复制(intPtr,managedBuf,0,size);
System::IO::Stream ^ms=gcnew System::IO::MemoryStream();
ms->Write(managedBuf,0,大小);