2011-10-10 21 views
7

Projemde C# C++ CLR işlevinden bir bayt [] geçiriyorum.C++ CLR dizisinde <System :: Byte> dizisi nasıl dönüştürülür?

C++ CLR kodu:

void TestByteArray(array<System::Byte>^ byteArray) 
{ 
    ... 
} 

C# kodu: TestByteArray() fonksiyonunda

byte[] bytes = new byte[128]; 
... 
TestByteArray(bytes); 

, ben yerel C kullanmış, böylece * char ByteArray dönüştürmek gerek ++ kodu . Bu dönüşümü nasıl yapabilirim?

cevap

14
void TestByteArray(array<System::Byte>^ byteArray) 
{ 
    pin_ptr<System::Byte> p = &byteArray[0]; 
    unsigned char* pby = p; 
    char* pch = reinterpret_cast<char*>(pby); 

    // use it... 
} 
+0

Çalışıyor, teşekkür arıyoruz! – Spark

İlgili konular