Laden...

DllImport: Marshalling Probleme mit Skyhooks WPS SDK

Erstellt von markus111 vor 13 Jahren Letzter Beitrag vor 13 Jahren 1.201 Views
markus111 Themenstarter:in
479 Beiträge seit 2008
vor 13 Jahren
DllImport: Marshalling Probleme mit Skyhooks WPS SDK

Hallo,

ich schreibe mir gerade einen .NET Wrapper für die Skyhooks Wireless Positioning System (kurz WPS) SDK.

Die Position wird in folgender Struktur (C) zurückgegeben (als Pointer im Parameter):

typedef struct
{
    double latitude;
    double longitude;
    double hpe;
    unsigned short nap;
    double speed;
    double bearing;
    WPS_StreetAddress* street_address;
    unsigned short ncell;
    unsigned short nsat;
    double altitude;
    WPS_LocationType type;
} WPS_Location;

Meine C# struct dazu:

    [StructLayout(LayoutKind.Sequential)]
    public struct Location
    {
        public double latitude;
        public double longitude;
        public double hpe;
        public ushort nap;
        public double speed;
        public double bearing;
        public StreetAddress street_address;
        public ushort ncell;
        public ushort nsat;
        public double altitude;
        public LocationType type;
    }

LocationType ist ein enum, StreetAddress auch eine struct:
In C:

typedef struct
{
    char* street_number;
    char** address_line;
    char* city;
    char* postal_code;
    char* county;
    char* province;
    WPS_NameCode state;
    char* region;
    WPS_NameCode country;
} WPS_StreetAddress;

Dazu meine C# struct:

    [StructLayout(LayoutKind.Sequential)]
    public struct StreetAddress
    {
        public string street_number;
        public string address_line;
        public string city;
        public string postal_code;
        public string county;
        public string province;
        public NameCode state;
        public string region;
        public NameCode country;
    }

Die Location-Struct bekomme ich mit folgender Funktion (C):

WPSAPI_EXPORT WPS_ReturnCode WPSAPI_CALL
WPS_location(const WPS_SimpleAuthentication* authentication,
             WPS_StreetAddressLookup street_address_lookup,
             WPS_Location** location);

Mein DllImport dazu:

        [DllImport(LibraryName)]
        public static extern ReturnCode WPS_location(ref SimpleAuthentication authentication,
            StreetAddressLookup street_address_lookup,
            out Location location);

Problem: In C bekomme ich meine Position, also der Service funktioniert. In C# ist die Location-struct mit en gefüllt, bis auf latitude, die ist 2.40895602708386E-315. Die StreetAddress-struct enthält nur null-Variablen (alle strings sind null).
Weiß jemand was ich falsch Marshalle? Hab schon vieles durchprobiert - ohne erfolg...
Die WPS_location-Funktion gibt aber WPS_OK zurück.

mfg.
markus111

[Follow me on Twitter](http://twitter.com/blendingsky)
B
6 Beiträge seit 2010
vor 13 Jahren

.NET erwartet ja standardmäßig Unicode-Strings, wenn ich mich richtig erinnere, vielleicht liegt es daran, also einfach mal
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
oder
[MarshalAs(UnmanagedType.LPStr)] public string ...
probieren

markus111 Themenstarter:in
479 Beiträge seit 2008
vor 13 Jahren

Hm, hab rausgefunden das die Auth-Strings korrekt übermittelt werden, nur ich bekomme die Location-Structur falsch zurück. In C gehts...

mfg.
markus111

[Follow me on Twitter](http://twitter.com/blendingsky)