> I have two questions about MarshalAs
>
[quoted text clipped - 27 lines]
>
> Would someone please correct my direction on these two questions??
1) The struct information alone isn't enough; what is the unmanaged
signature of the function that consumes this struct?
2) Again the unmanaged definition for the callee would be required before
any useful advice could be offered.

Signature
Kevin Westhead
Tony Farrell - 14 Sep 2003 01:15 GMT
> > I have two questions about MarshalAs
> >
[quoted text clipped - 33 lines]
> 2) Again the unmanaged definition for the callee would be required before
> any useful advice could be offered.
Hi Kevin and everyone -
Here is the answer to your first question -
[DllImport("CarChipSDK", EntryPoint="GetTripRecord")]
public static extern bool GetTripRecord
(
int index,
TripRecord_struct trip_record
);
Here is the full struct that i am trying to work with....
[StructLayout(LayoutKind.Sequential)]
public struct TripRecord_struct
{
[MarshalAs( UnmanagedType.Struct)]
public DateTimeStruct startTime;
[MarshalAs( UnmanagedType.Struct)]
DateTimeStruct endTime;
[MarshalAs( UnmanagedType.Struct)]
DateTimeStruct tripDuration;
double maxSpeed;
double avgSpeed;
double distance;
int hardBrakeCount;
int extremeBrakeCount;
int hardAccelerationCount;
int extremeAccelerationCount;
[MarshalAs( UnmanagedType.ByValArray, SizeConst=5)]
int parameter; /*!< int parameter[5] */
[MarshalAs( UnmanagedType.ByValArray, SizeConst=5)]
int samplingInterval;
[MarshalAs( UnmanagedType.ByValArray, SizeConst=5)]
bool parameterSupported; /*!< bool parameterSupported[5] */
[MarshalAs( UnmanagedType.ByValArray, SizeConst=3)]
double speedThreshold; /*!< double speedThreshold[3] */
double hardBrakeThreshold;
double extremeBrakeThreshold;
double hardAccelerationThreshold;
double extremeAccelerationThreshold;
bool disconnectedDuringTrip;
};
Thanks for taking the time to help!!
take care
tony
Kevin Westhead - 14 Sep 2003 18:46 GMT
[snip]
> [DllImport("CarChipSDK", EntryPoint="GetTripRecord")]
> public static extern bool GetTripRecord
[quoted text clipped - 30 lines]
> bool disconnectedDuringTrip;
> };
Mattias' response should provide what you need. I've modified the struct
above based on his answers.

Signature
Kevin Westhead
Tony,
>What would the correct MarshalAs statement be?
>
>This is what i'm trying...
> [MarshalAs( UnmanagedType.Struct)]
> DateTimeStruct startTime;
If you have a DateTimeStruct member inside another struct, you don't
need any MarshalAs attribute on it.
UnmanagedType.Struct has nothing to do with C# structs, it should have
been called UnmanagedType.Variant instead.
>2) Given this struct element -
>int samplingInterval[5]
[quoted text clipped - 4 lines]
> [MarshalAs( UnmanagedType.ByValArray, SizeConst=5)]
> int samplingInterval;
[MarshalAs( UnmanagedType.ByValArray, SizeConst=5)]
int[] samplingInterval;
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.