我有一些 C 代码,我试图从 C# 中使用。大部分转换已完成。我有几个问题。
部分“C”代码如下所示。
typedef struct r_GetCPL {
UInt8 Storage;
UInt8 Key[16]; //(1)
UInt8 *Buff; //(2)
Array16 *CryptoKeyIDs; //(3)
} REPLY_GETCPL;
在“C”中定义的别名
typedef unsigned char UInt8;
typedef unsigned short UInt16;
typedef unsigned long UInt32;
typedef unsigned long long UInt64;
typedef UInt8 Array8[8];
typedef UInt8 Array16[16];
typedef UInt8 Array32[32];
typedef UInt8 Array64[64];
typedef UInt8 Array128[128];
我假设我可以用直接结构定义替换 typedef。这样好吗?我定义的等效 C# 结构是,
public struct REPLY_GETCPL
{
Byte Storage;
Byte[16] Key; //(1) Is this right?
UInt8 *Buff; //(2) What is the equivalent?
Array16 *CryptoKeyIDs; //(3) What is the equivalent?
}
另外,有几种方法导入我被困在
void hex_print(char* data, UInt32 length);
DRMKLVItem *NewDRMKLVItem(UInt32 lenBuff, UInt32 cmdId);
RESULT DRMKLVLengthDecode(const UInt8 *s, UInt32 *pLen);
C#
//I think this one is defined right
[DllImport("DoremiSource.dll")]
public static extern void hex_print([MarshalAs(UnmanagedType.LPStr)]string data, UInt32 length);
//(How to convert the function return type?)
[DllImport("DoremiSource.dll")]
public static extern DRMKLVItem *NewDRMKLVItem(UInt32 lenBuff, UInt32 cmdId); //(4)
//(How do i convert the function parameters here)
[DllImport("DoremiSource.dll", CharSet = CharSet.Ansi)]
public static extern int DRMKLVLengthDecode(const UInt8 *s, ref UInt32 pLen); //(5)