2010-02-03 59 views
0

我试图从C#调用一个函数用C虽然C++转换阵列<Byte> ^数据为const字节*数据 - C++/CLR

所以基本上C# - > C++ - “ç

在C#,我有字节[]字节 - 从文件中读取信息。我将字节数组和大小传递给C++。

在C++中,我得到了字节数组和大小,但我无法转换为特定的数据类型。

void Image::OpenMemFile(array<Byte>^ data, unsigned int size) 
{ 

    Free(); 
    m_dataStream = data; 
    Byte const* streamData = &data[0]; // this is where it throws error 
     // Should I use marshaling here ? What call should that ;be ? 
     hImage = ::OpenMemImage(streamData ,&nbsp;size); 
    modified = false; 
} 

// this is the function I&nbsp;need to call 
EXIVSIMPLE_API HIMAGE OpenMemImage(const&nbsp;BYTE *data, unsigned int size) 
{ 
    // code 
     imgWrap->image = Exiv2::ImageFactory::open(data, size); 

} 

需要调用C函数是

Image::AutoPtr ImageFactory::open(const byte* data, long size) 
    { 
     /// code 
    } 

我需要在字节数组转换为const BYTE *提供帮助。我意识到我需要使用马沙拉。是否有一个特定的函数来封送C++中的数组?

任何帮助表示赞赏。

谢谢

回答

1
pin_ptr<unsigned char> pin_buffer = &data[0]; 
unsigned char* pData = pin_buffer;