I have the following structure in C++. I would like to define it in C#. How to do that. Anyone have some thoughts
typedef struct AccessibleTableInfoTag {
JOBJECT64 caption; // AccesibleContext
JOBJECT64 summary; // AccessibleContext
jint rowCount;
jint columnCount;
JOBJECT64 accessibleContext;
JOBJECT64 accessibleTable;
} AccessibleTableInfo;
I tried it the following way to convert the AccessibleTableInfo tag in C#. But it does not work.
[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
}
But it does not work.
I resolved the following way
[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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.