C#元帅typedef char T_STRING [MAX_STRING_SIZE] [英] C# Marshal typedef char T_STRING[MAX_STRING_SIZE]
本文介绍了C#元帅typedef char T_STRING [MAX_STRING_SIZE]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何指挥:
[C++]
#define MAX_STRING_SIZE 255
typedef char T_STRING[MAX_STRING_SIZE];
typedef struct
{
unsigned long m_ID;
T_STRING m_name;
} Result;
在C#中?
当前我正在执行此操作(但它不起作用):
Currently I am doing this (but it does not work):
[C#]
[StructLayout(LayoutKind.Sequential)]
public struct Result
{
public uint m_ID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
public char[] m_name;
}
我尝试使用IntPtr代替char [],但结果不尽相同.有和没有[MarshalAs(...)].
I have tried to use a IntPtr instead of char[] with equal non-working result. Both with and without [MarshalAs(...)].
推荐答案
将其编组为:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Result
{
public uint m_ID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
public string m_name;
}
这篇关于C#元帅typedef char T_STRING [MAX_STRING_SIZE]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文