473,473 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

UnmanagedType.LPArray in structure

1 New Member
Hello

My programm receives array of bytes over SSL from Delphi program.
I convert it into structure and have en error:
Type 'SetOrder' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed

Delphi:
Expand|Select|Wrap|Line Numbers
  1. TTLVHADPrefix = packed record
  2.   ProtocolID: TProtocolID;
  3.   Version: Byte;
  4. end;
Expand|Select|Wrap|Line Numbers
  1. TTLVHAD = packed record
  2.   Prefix: TTLVHADPrefix;
  3.   Len: DWORD;
  4.   TermID: TTermID;
  5.   OperCode: WORD;
  6. end;
  7.  
Expand|Select|Wrap|Line Numbers
  1. TTLV602 = packed record
  2.   Header: TTLVHAD;
  3.   AccNumLen: WORD;
  4.   AccNum: array of Char;
  5.   AccType: Char;
  6.   Status: Char;
  7. end;

My C#

Expand|Select|Wrap|Line Numbers
  1.         [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
  2.         public struct TlvHad
  3.         {
  4.             [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
  5.             public Char[] tlv;          
  6.             public Byte protocolVer; 
  7.         }
  8.  
Expand|Select|Wrap|Line Numbers
  1.         [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
  2.         public struct HeaderQry
  3.         {
  4.             public TlvHad prefix; 
  5.             public UInt32 len;
  6.             [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
  7.             public Char[] termID; 
  8.             public UInt16 operCode;
  9.         }
  10.  
Expand|Select|Wrap|Line Numbers
  1.        [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
  2.         public struct SetOrder
  3.         {
  4.             public HeaderQry headerQry; 
  5.             public UInt16 AccNumLen;    
  6.             [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=12)]
  7.             public Char[] AccNum;       
  8.             public Char Type;           
  9.             public Char Status;         
  10.         }
  11.  
  12.  

Expand|Select|Wrap|Line Numbers
  1.         public static object Deserialize(byte[] rawdatas, Type anytype)
  2.         {
  3. ERROR THIS  int rawsize = Marshal.SizeOf(anytype);
  4.             if (rawsize > rawdatas.Length)
  5.                 return null;
  6.             GCHandle handle = GCHandle.Alloc(rawdatas, GCHandleType.Pinned);
  7.             IntPtr buffer = handle.AddrOfPinnedObject();
  8.             object retobj = Marshal.PtrToStructure(buffer, anytype);
  9.             handle.Free();
  10.             return retobj;
  11.         }
  12.  
  13.  
May 25 '11 #1
1 8439
bvrwoo
16 New Member
I am not sure that you can marshal the size of anytype because you can only marshal structures I believe do the CLR reallocating the heap which you cannot control. Thus is the same reason you cannot use the fixed keyword on a class type to point to. In cases like this it is far better to use C++/CLI.
Aug 29 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Mick | last post by:
Does anyone know how to pass an array of structures to a DLL? Here's what I'm doing... the VB.Net error is at the end. *** C++ Structure Declaration: typedef struct _SOME_STRUCT { char...
2
by: Mel WEaver | last post by:
Hello, I have the following delphi structure for a binary file. I'm looking for idea how to read this file. Mel type TMenuDataStruct = packed record exename : string;
2
by: vikas | last post by:
I have following structure in c++. typedef struct MMF_result_struct { int action; char text; int cols,rows; int month,day,year; } MMF_result; Now this structure is shared between C++ and C#...
1
by: Betty | last post by:
When marshalling a char array in a structure from C to .NET, I get the following error: System.ArgumentException: Type could not be marshaled because the length of an embedded array instance does...
6
by: Laurent | last post by:
Hello, This is probably a dumb question, but I just would like to understand how the C# compiler computes the size of the managed structure or classes. I'm working on this class: public...
10
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
3
by: =?Utf-8?B?VG9tIEFsbGVu?= | last post by:
We are using a 3rd party API that processes video stream files to update a data structure in the file. I am writting a C# facade for this API but I am having a hard time getting it to pass data...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
10
by: Scott Townsend | last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent it to be in specific places (not yet 100% defined). I wanted to create a structure/class with all of the data in it...
7
by: edsunder | last post by:
I'm making a "wrapper" for an unmanaged DLL (written, I'm fairly certain in C). I have a c++ "wrapper" that I'm trying to convert to VB.net. I've got most of the program working, but I've hit a brick...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.