如何在c#中定义AccessibleTableInfo
本文关键字:定义 AccessibleTableInfo | 更新日期: 2023-09-27 18:19:06
我在c++中有以下结构。我想在c#中定义它。怎么做呢?有人有什么想法吗?
typedef struct AccessibleTableInfoTag {
JOBJECT64 caption; // AccesibleContext
JOBJECT64 summary; // AccessibleContext
jint rowCount;
jint columnCount;
JOBJECT64 accessibleContext;
JOBJECT64 accessibleTable;
} AccessibleTableInfo;
我尝试了以下方法来转换c#中的AccessibleTableInfo标签。但这行不通。
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct AccessibleTableInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string caption;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string summary;
[MarshalAs(UnmanagedType.I4)]
public int rowCount;
[MarshalAs(UnmanagedType.I4)]
public int columnCount;
[MarshalAs(UnmanagedType.LPStruct)]
public AccessibleContextInfo accessibleContext;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.LPStruct)]
public AccessibleContextInfo accessibleTable;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct AccessibleContextInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string name; // the AccessibleName of the object
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string description; // the AccessibleDescription of the object
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string role; // localized AccesibleRole string
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string role_en_US; // AccesibleRole string in the en_US locale
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string states; // localized AccesibleStateSet string (comma separated)
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string states_en_US; // AccesibleStateSet string in the en_US locale (comma separated)
public Int32 indexInParent; // index of object in parent
public Int32 childrenCount; // # of children, if any
public Int32 x; // screen coords in pixels
public Int32 y; // "
public Int32 width; // pixel width of object
public Int32 height; // pixel height of object
public Boolean accessibleComponent; // flags for various additional
public Boolean accessibleAction; // Java Accessibility interfaces
public Boolean accessibleSelection; // FALSE if this object doesn't
public Boolean accessibleText; // implement the additional interface
// in question
// BOOL accessibleValue; // old BOOL indicating whether AccessibleValue is supported
public Boolean accessibleInterfaces; // new bitfield containing additional interface flags
}
我解决了以下问题
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct AccessibleTable
{
[MarshalAs(UnmanagedType.I4)]
public int index;
[MarshalAs(UnmanagedType.I4)]
public int row;
[MarshalAs(UnmanagedType.I4)]
public int column;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct AccessibleTableInfo
{
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=2)]
public string caption;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=2)]
public string summary;
[MarshalAs(UnmanagedType.I4)]
public int rowCount;
[MarshalAs(UnmanagedType.I4)]
public int columnCount;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.LPStruct)]
public AccessibleContextInfo[] accessibleContext;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.LPStruct)]
public AccessibleTable[] accessibleTable;
}