C# 绑定到iOS静态库时从Monotouch访问Objective-C结构

C# 绑定到iOS静态库时从Monotouch访问Objective-C结构,c#,ios,objective-c,xamarin.ios,xamarin,C#,Ios,Objective C,Xamarin.ios,Xamarin,我有一些第三方iOS静态库,其中的.h文件包含const struct: struct SomeStruct { __unsafe_unretained NSString * const FirstName; __unsafe_unretained NSString * const SecondName; __unsafe_unretained NSString * const ThirdName; }; extern const struct SomeStruct

我有一些第三方iOS静态库,其中的.h文件包含
const struct

struct SomeStruct
{
    __unsafe_unretained NSString * const FirstName;
    __unsafe_unretained NSString * const SecondName;
    __unsafe_unretained NSString * const ThirdName;

};

extern const struct SomeStruct someName;
我将这个静态库绑定到MonoTouch,但我不知道如何在C#中复制它并从该结构中访问字符串值

SomeInterface.Name.FirstName;
在MonoTouch iOS绑定项目中

public struct SomeStruct
{
    public string FirstName;
    public string SecondName;
    public string ThirdName;

};


[Static]
public interface SomeInterface
{

    [Field ("SomeStruct", "__Internal")]
    IntPtr someNameStr { get; }
}
我将iOS绑定项目生成的dll包含在我的演示应用程序中

访问结构

    public static SomeStruct Name {
        get {
            if (SomeInterface.someNameStr != IntPtr.Zero) {
                return (SomeStruct)Marshal.PtrToStructure<SomeStruct> (SomeInterface.someNameStr);
            }
            return new SomeStruct ();
        }
    }
那么,有人能帮我吗


提前感谢。

您想使用Dlfcn中的方法获取someName地址的地址。使用dlopen打开库,使用dlsym获取地址

然后可以使用marshal.PtrToStructure封送结果,但必须确保值为IntPtr,如下所示:

public struct SomeStruct
{
    IntPtr _FirstName;
    IntPtr _SecondName;
    IntPtr _ThirdName;
};
要获取字符串,请执行以下操作:

    public string FirstName {
        get {
            return (string) (new NSString (_FirstName));
        }
    }

@DasBinkenLight感谢您的编辑。您能告诉我如何访问SomeStruct结构吗?ptrStructure会这样做。