473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Passing complex data structure to non-COM DLL function.

aaa
I am having trouble getting a complex data type to get passed to a non-COM
dll's function by ref and return back data from that object. Simple data
types work fine but when I try the complex data types, with the class it
simply initializes but returns nothing. The struct I have tried several
different ways all of them either erros or the app simply closes out
(usually when I try to pass the struct with the ref keyword). Any help would
be appreciated.
//TRIP LOGS
[DllImport("NonCOM.dll")]
public static extern bool GetTripRecord (int index,DataTypes.TripRecord
record);
public static bool GetTripRecordA(int index,DataTypes.TripRecord record)
{
return GetTripRecord(index,record);
}

[DllImport("NonCOM.dll", EntryPoint="GetTripRecord")]
public static extern int GetNumTripRecs();
public static int GetNumTripRecs_()
{
return GetNumTripRecs();
}

DataTypes.TripRecord tripRecord=new DataTypes.TripRecord();


for(int q=0;q<ICarChip.GetNumTripRecsA();q++) //returns a rec count of
11
{
ICarChip.GetTripRecordA(q,tripRecord); //passing in class right now

x1 = tripRecord.startTime;
x2 = tripRecord.endTime;
x3 = tripRecord.tripDuration;
x4 = tripRecord.maxSpeed;
x5 = tripRecord.avgSpeed;
x6 = tripRecord.distance;
x7 = tripRecord.hardBrakeCount;
x8 = tripRecord.extremeBrakeCount;
x9 = tripRecord.hardAccelerationCount;
x10 = tripRecord.extremeAccelerationCount;
x11 = tripRecord.parameter;
x12 = tripRecord.samplingInterval;
x13 = tripRecord.parameterSupported;
x14 = tripRecord.speedThreshold;
x15 = tripRecord.hardBrakeThreshold;
x16 = tripRecord.extremeBrakeThreshold;
x17 = tripRecord.hardAccelerationThreshold;
x18 = tripRecord.extremeAccelerationThreshold;
x19 = tripRecord.disconnectedDuringTrip;

}


public class DataTypes
{

[StructLayout(LayoutKind.Sequential)]
public class TripRecord
{
public DateTime startTime;
public DateTime endTime;
public DateTime tripDuration;
public double maxSpeed;
public double avgSpeed;
public double distance;
public int hardBrakeCount;
public int extremeBrakeCount;
public int hardAccelerationCount;
public int extremeAccelerationCount;
public int parameter;
public int samplingInterval;
public bool parameterSupported;
public double speedThreshold;
public double hardBrakeThreshold;
public double extremeBrakeThreshold;
public double hardAccelerationThreshold;
public double extremeAccelerationThreshold;
public bool disconnectedDuringTrip;
}

[StructLayout(LayoutKind.Sequential)]
public struct DateTimeStruct
{
public int year;
public int month;
public int day;
public int hour;
public int minute;
public int second;
}

[StructLayout(LayoutKind.Sequential)]
public struct TripRecord_struct
{

public DateTimeStruct startTime;
public DateTimeStruct endTime;
public DateTimeStruct tripDuration;
public double maxSpeed;
public double avgSpeed;
public double distance;
public int hardBrakeCount;
public int extremeBrakeCount;
public int hardAccelerationCount;
public int extremeAccelerationCount;
[MarshalAs( UnmanagedType.ByValArray, SizeConst=5)]
public int[] parameter; /*!< int parameter[5] */
[MarshalAs( UnmanagedType.ByValArray, SizeConst=5)]
public int[] samplingInterval;
[MarshalAs( UnmanagedType.ByValArray, SizeConst=5)]
public bool[] parameterSupported; /*!< bool parameterSupported[5] */
[MarshalAs( UnmanagedType.ByValArray, SizeConst=3)]
public double[] speedThreshold; /*!< double speedThreshold[3] */
public double hardBrakeThreshold;
public double extremeBrakeThreshold;
public double hardAccelerationThreshold;
public double extremeAccelerationThreshold;
public bool disconnectedDuringTrip;
};

public DataTypes()
{
//
// TODO: Add constructor logic here
//
}
}
Nov 16 '05 #1
3 2187

You have to show us the original native type declaration, without it
it's hard to know if you've made any conversion errors.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
aaa
Sorry:

---orig function def----------
bool GetTripRecord ( int index,
TripRecord * record
)

Retrieve a downloaded trip record.
Parameters:
index - trip index 0 - first trip
record - see Structures.h

Return values:
true if record was successfully retrieved

---Public Attributes----
DateTimeStruct startTime
DateTimeStruct endTime
DateTimeStruct tripDuration
double maxSpeed
double avgSpeed
double distance
int hardBrakeCount
int extremeBrakeCount
int hardAccelerationCount
int extremeAccelerationCount
int parameter [5]
int samplingInterval [5]
bool parameterSupported [5]
double speedThreshold [3]
double hardBrakeThreshold
double extremeBrakeThreshold
double hardAccelerationThreshold
double extremeAccelerationThreshold
bool disconnectedDuringTrip


"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:ut**************@TK2MSFTNGP10.phx.gbl...

You have to show us the original native type declaration, without it
it's hard to know if you've made any conversion errors.

Mattias

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

Nov 16 '05 #3

Well the TripRecord_struct structure looks more or less correct. You
may have to specify [MarshalAs(UnmanagedType.I1)] on the bool members
though.

And you should pass this as a ref parameter to the function. That
doesn't work?


Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Linux Inquirer | last post by:
Hi Guys, I need to pass a C structure of this form from VB6 <-> VC++ 6 struct BTag { int rowIndex; BSTR* valueList; } B;
0
by: Marc te Vruchte | last post by:
Over the past years i've been in contact with the same problem a number of times, creating a graphical user interface on complex XML documents. Personally these solutions have never been...
0
by: Kirk Marple | last post by:
i have a large C++ data structure that i'm trying to interop with... the structure is 77400 bytes long. i have the structure defined in C#, so i was trying to just use "ref <structure>" as the...
3
by: andreas.baus | last post by:
Hello. I'm trying to exchange data between a webservice based on Apache Axis and a client written in C#, and so far it has been working with few problems (none that I couldn't solve myself with...
2
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Have a complex process where I need to Import a large amount of data then run some transformations on this data then import into DataBase. The transformation involves multiple fields and multiple...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.