473,468 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Marshal.PtrToStructure problem !!

Hi,
I have two C++ structures like these :

typedef struct answer_series_item
{
int32_t contract_size_i;
int32_t price_quot_factor_i;
char ins_id_s [32];
char isin_code_s [12];
uint8_t suspended_c;
char date_last_trading_s [8];
char time_last_trading_s [6];
char settlement_date_s [8];
char start_date_s [8];
char end_date_s [8];
char date_delivery_start_s [8];
char date_delivery_stop_s [8];
uint8_t series_status_c;
} answer_series_item_t;

typedef struct answer_series
{
uint16_t segment_number_n;
uint16_t items_n;
answer_series_item_t item [400];
} answer_series_t;
The first is present 400 times in the second one.

I have create in C# these two structures but when I try to Marshar I
rise an error.

C# Structures
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public class answer_series_t
{
[MarshalAs(UnmanagedType.I2)] public Int16 segment_number_n;
[MarshalAs(UnmanagedType.I2)] public Int16 items_n;
[MarshalAs(UnmanagedType.Struct, SizeConst=6)] public
answer_series_item_t [] item = new answer_series_item_t[6];
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public class answer_series_item_t
{
[MarshalAs(UnmanagedType.I4)] public Int32 contract_size_i;
[MarshalAs(UnmanagedType.I4)] public Int32 price_quot_factor_i;
[MarshalAs(UnmanagedType.ByValArray ,SizeConst =32)] public char
[]ins_id_s = new char[32];
[MarshalAs(UnmanagedType.ByValArray ,SizeConst =12)] public char
[]isin_code_s = new char[12];
[MarshalAs(UnmanagedType.U1)] public char suspended_c;
[MarshalAs(UnmanagedType.ByValArray ,SizeConst =8)] public char
[]date_last_trading_s = new char[8];
[MarshalAs(UnmanagedType.ByValArray ,SizeConst =6)] public char
[]time_last_trading_s = new char[6];
[MarshalAs(UnmanagedType.ByValArray ,SizeConst =8)] public char
[]settlement_date_s = new char[8];/
[MarshalAs(UnmanagedType.ByValArray ,SizeConst =8)] public char
[]start_date_s = new char[8];
[MarshalAs(UnmanagedType.ByValArray ,SizeConst =8)] public char
[]end_date_s = new char[8];
[MarshalAs(UnmanagedType.ByValArray ,SizeConst =8)] public char
[]date_delivery_start_s = new char[8];
[MarshalAs(UnmanagedType.ByValArray ,SizeConst =8)] public char
[]date_delivery_stop_s = new char[8];
[MarshalAs(UnmanagedType.I1)] public char series_status_c;
}

From the C++ DLL I have the memory pointer.

I use this command :

Marshal.PtrToStructure(mypointer, mystructure);

Where mypointer is the pointer from C++ and mystructure is a new
istance of the c# structure.

The error message is (sorry but is in Italian..):

Impossibile effettuare il marshalling del campo item del tipo
answer_series_t. Non è possibile effettuare il marshalling di questo
tipo come campo struttura.

Where is my mistake ? :evil:
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 15 '05 #1
1 3913

See http://www.dotnetinterop.com/faq/?q=...ithStructArray

Mattias

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

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

Similar topics

0
by: William Stacey | last post by:
The following code works, but I can't figure out why. I take a struct with two members, a single byte and byte. I then marshal the whole struct to a byte. I create a new struct (without init'ing...
1
by: Ken Allen | last post by:
The documentation is not clear on the exact behaviour of the Marshal.PtrToStructure method and whether it copies the contents of the IntPtr region to a new managed object or whether it creates the...
2
by: John | last post by:
public const int FRAME_LENGTH=144; public class FRAME_T { public byte Block = new byte; } public void MyDataHandler(IntPtr appContext, IntPtr data) FRAME_T frame = new FRAME_T();...
1
by: dhornyak | last post by:
I have been banging my head against the wall for a while now, and can't seem to id the problem. I've been through a ton of posts and the code doesn't seem any different. Can anybody see it? When...
1
by: Jay | last post by:
Hi, In my application, C++ dll is posting some message,which is processed by a form in C# ,where I use Message.Lparam to convert it in structure using Marshal.PtrToStructure() mehtod ,but it...
1
by: spamacon | last post by:
Hello, I have a strange situation using .Net FW 1.1. I want to use Marshal.PtrToStructure to fill the structure below. The first 3 fields get filled correctly: ulStruct describes how big the...
0
by: krascso | last post by:
Hi everybody. I have a structure in unmanaged C++: struct TLogonParams { char name; char pswd; char alias;
0
by: P Laxmi | last post by:
I have following two structures in vc++ and i want to convert it into c# typedef struct { ULONG CallRef ; ULONG CallSource ; ULONG ...
2
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the original byte array. What do I need to specify to get...
0
by: Charming12 | last post by:
Hi All, I have a strange problem and due to my inefficiency with IntPtr i am unable to figure it out. I have an structure something like: public struct Detail { public int age; public...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.