111,095
社区成员




static string[] tttt_post_default_names = { ".notdef", ".null", "CR", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand" };
#if USING_POSTSCRIPT_NAMES
static string GET_MAC_NAME(int x)
{
return ptrnames.macintosh_name(x);
}
#else
static string GET_MAC_NAME(int x)
{
return tttt_post_default_names[x];
}
#endif
void doSomething(IntPtr ptr, int len)
{
}
void main()
{
byte[] bytes = new byte[100];
IntPtr ptr = Marshal.AllocHGlobal(100);
Marshal.Copy(bytes, 0, ptr, 100);
IntPtr newPtr = Marshal.ReadIntPtr(ptr, 20); //这里:指针首地址偏移20
doSomething(newPtr, 10);
public readonly string[258] tttt_post_default_names =
{
".notdef", ".null", "CR", "space", "exclam",
"quotedbl", "numbersign", "dollar", "percent", "ampersand",
};
void doSomething(byte[] ptr, int len)
{
}
void main()
{
byte[] buf = new char[100];
doSomething(buf[],10);
}
public delegate int ValueFunc(string glyph_name );
public delegate string NameFunc( int name_index );
里面的那个红替换,转换出来怪怪的:
typedef struct MY_Service_TestServiceRec_ FT_Service_TestServiceRec ;
typedef struct MY_Service_TestServiceRec_ const * MY_Service_TestService ;
struct MY_Service_TestServiceRec_
{
ValueFunc unicode_value;
NameFunc macintosh_name;
};
让我有点莫名!在C#里,没有typedef ,直接使用原始结构体定义的名称:
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi )]
public struct MY_Service_TestServiceRec_{
public ValueFunc unicode_value;
public NameFunc macintosh_name;
}
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi )]
public struct MY_Frame_Field{
public byte value;
public byte size;
public ushort offset;
}
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi )]
public struct TestHeader{
public int Version;
public short Ascender;
public short Descender;
public short Line_Gap;
}
//这个就是莫名的地方
C++:
const MY_Frame_Field test_header_fields[] =
{
{ 0, 0, 10 },
{ 1, FT_FIELD_SIZE( Version ), FT_FIELD_OFFSET( Version ) },
{ 2, FT_FIELD_SIZE( Ascender ), FT_FIELD_OFFSET( Ascender ) },
{ 2, FT_FIELD_SIZE( Descender ), FT_FIELD_OFFSET( Descender ) },
{ 2, FT_FIELD_SIZE( Line_Gap ), FT_FIELD_OFFSET( Line_Gap ) },
{ 100, 0, 0 }
};
C#
public readonly MY_Frame_Field test_header_fields[] =
{
{ 0, 0, 10 },
{ 1, FT_FIELD_SIZE( Version ), FT_FIELD_OFFSET( Version ) },
{ 2, FT_FIELD_SIZE( Ascender ), FT_FIELD_OFFSET( Ascender ) },
{ 2, FT_FIELD_SIZE( Descender ), FT_FIELD_OFFSET( Descender ) },
{ 2, FT_FIELD_SIZE( Line_Gap ), FT_FIELD_OFFSET( Line_Gap ) },
{ 100, 0, 0 }
}
[StructLayout(LayoutKind.Sequential)]
public struct st_test_function
{
public int m;
public int n;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public FloatStru[] domain;
public int hasrange;
public UStru u;
};
[StructLayout(LayoutKind.Sequential)]
public struct FloatStru
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2)]
public float[] a;
};
[StructLayout(LayoutKind.Explicit)]
public struct UStru
{
[FieldOffset(0)]
public ST_00 st_00;
[FieldOffset(0)]
public ST_01 st_01;
[FieldOffset(0)]
public ST_02 st_02;
};
[StructLayout(LayoutKind.Sequential)]
public struct ST_00
{
public ushort bps;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public int[] size;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public FloatStru[] encode;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public FloatStru[] decode;
public System.IntPtr samples;
};
[StructLayout(LayoutKind.Sequential)]
public struct ST_01
{
public float n;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public float[] c0;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public float[] c1;
}
[StructLayout(LayoutKind.Sequential)]
public struct ST_02
{
public int k;
public IntPtr funcs;
public IntPtr bounds;
public IntPtr encode;
}
void doSomething(char[] buf, ptr, int len)
{
}
void main()
{
usigned char[] buf = new char[100];
doSomething(buf[20],10);
}