问题来源:C++调用C#的dll时候,需要响应的类型转换
array<unsigned char>^ GetBYTECLI(unsigned char *pszName,int nStrLen)
{
array<unsigned char>^ bs = gcnew array<unsigned char>(nStrLen);
for(int i = 0;i<nStrLen;i++)
{
bs[i] = pszName[i];
}
return bs;
}
unsigned char* GetBYTE(array<unsigned char>^ pszName)
{
unsigned char *b2 = new unsigned char(pszName->Length);
//pin_ptr<unsigned char> pb1 = &pszName[0];
for(int i=0;i<pszName->Length;i++)
{
//b2[i] = *(pb1+i);
b2[i] = pszName[i];
}
//memcpy(b2,pb1,pszName->Length);
return b2;
}
unsigned char *pszName = (unsigned char*)charArray;
unsigned char *b2 = new unsigned char(pszName->Length);
参考:http://stackoverflow.com/questions/15078638/can-i-turn-unsigned-char-into-char-and-vice-versa