473,655 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("NonC OM.dll")]
public static extern bool GetTripRecord (int index,DataTypes .TripRecord
record);
public static bool GetTripRecordA( int index,DataTypes .TripRecord record)
{
return GetTripRecord(i ndex,record);
}

[DllImport("NonC OM.dll", EntryPoint="Get TripRecord")]
public static extern int GetNumTripRecs( );
public static int GetNumTripRecs_ ()
{
return GetNumTripRecs( );
}

DataTypes.TripR ecord tripRecord=new DataTypes.TripR ecord();


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

x1 = tripRecord.star tTime;
x2 = tripRecord.endT ime;
x3 = tripRecord.trip Duration;
x4 = tripRecord.maxS peed;
x5 = tripRecord.avgS peed;
x6 = tripRecord.dist ance;
x7 = tripRecord.hard BrakeCount;
x8 = tripRecord.extr emeBrakeCount;
x9 = tripRecord.hard AccelerationCou nt;
x10 = tripRecord.extr emeAcceleration Count;
x11 = tripRecord.para meter;
x12 = tripRecord.samp lingInterval;
x13 = tripRecord.para meterSupported;
x14 = tripRecord.spee dThreshold;
x15 = tripRecord.hard BrakeThreshold;
x16 = tripRecord.extr emeBrakeThresho ld;
x17 = tripRecord.hard AccelerationThr eshold;
x18 = tripRecord.extr emeAcceleration Threshold;
x19 = tripRecord.disc onnectedDuringT rip;

}


public class DataTypes
{

[StructLayout(La youtKind.Sequen tial)]
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 extremeBrakeCou nt;
public int hardAcceleratio nCount;
public int extremeAccelera tionCount;
public int parameter;
public int samplingInterva l;
public bool parameterSuppor ted;
public double speedThreshold;
public double hardBrakeThresh old;
public double extremeBrakeThr eshold;
public double hardAcceleratio nThreshold;
public double extremeAccelera tionThreshold;
public bool disconnectedDur ingTrip;
}

[StructLayout(La youtKind.Sequen tial)]
public struct DateTimeStruct
{
public int year;
public int month;
public int day;
public int hour;
public int minute;
public int second;
}

[StructLayout(La youtKind.Sequen tial)]
public struct TripRecord_stru ct
{

public DateTimeStruct startTime;
public DateTimeStruct endTime;
public DateTimeStruct tripDuration;
public double maxSpeed;
public double avgSpeed;
public double distance;
public int hardBrakeCount;
public int extremeBrakeCou nt;
public int hardAcceleratio nCount;
public int extremeAccelera tionCount;
[MarshalAs( UnmanagedType.B yValArray, SizeConst=5)]
public int[] parameter; /*!< int parameter[5] */
[MarshalAs( UnmanagedType.B yValArray, SizeConst=5)]
public int[] samplingInterva l;
[MarshalAs( UnmanagedType.B yValArray, SizeConst=5)]
public bool[] parameterSuppor ted; /*!< bool parameterSuppor ted[5] */
[MarshalAs( UnmanagedType.B yValArray, SizeConst=3)]
public double[] speedThreshold; /*!< double speedThreshold[3] */
public double hardBrakeThresh old;
public double extremeBrakeThr eshold;
public double hardAcceleratio nThreshold;
public double extremeAccelera tionThreshold;
public bool disconnectedDur ingTrip;
};

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

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 extremeBrakeCou nt
int hardAcceleratio nCount
int extremeAccelera tionCount
int parameter [5]
int samplingInterva l [5]
bool parameterSuppor ted [5]
double speedThreshold [3]
double hardBrakeThresh old
double extremeBrakeThr eshold
double hardAcceleratio nThreshold
double extremeAccelera tionThreshold
bool disconnectedDur ingTrip


"Mattias Sjögren" <ma************ ********@mvps.o rg> wrote in message
news:ut******** ******@TK2MSFTN GP10.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_stru ct structure looks more or less correct. You
may have to specify [MarshalAs(Unman agedType.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
4194
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
1836
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 satisfactory to me as a developer. I am not sure if this is caused by the way i've approached the problem or that it is the maturity of current day XML technologies. Let's say we are developing Form interfaces on complex XML documents which have a...
0
2236
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 method parameter. if i use this direct approach, i get the error: Message: Cannot marshal 'parameter #1': Internal limitation: structure is too complex or too large." is there a 64k limit on marshalling structures? what workarounds are there...
3
7299
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 a bit of web research). However, now I've tried passing complex data types between the two, and could not get that to work. What I did was to declare my data type on the Axis/Java side as an Object implementing java.io.Serializable, and when I...
2
1712
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 process - so the data needs to be read in 1 record at a time then run thru the transformation that may create new data value then everything is imported into a db to store. I have multiple questions 1)we used to have an internal data structure...
0
8380
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8296
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.