473,388 Members | 1,423 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,388 software developers and data experts.

Struct marshaling Problem

Hello everyone.
I'm trying to use CopyMemory API in VB.NET. I have a
module with struct defined like this:

<StructLayout(LayoutKind.Sequential)> _
Public Structure tSortKey
<VBFixedString(6),
System.Runtime.InteropServices.MarshalAs
(System.Runtime.InteropServices.UnmanagedType.ByVa lTStr,
SizeConst:=6)> Public CorpNum As Char()
<VBFixedString(15),
System.Runtime.InteropServices.MarshalAs
(System.Runtime.InteropServices.UnmanagedType.ByVa lTStr,
SizeConst:=15)> Public GlobalID As Char()
<VBFixedString(3),
System.Runtime.InteropServices.MarshalAs
(System.Runtime.InteropServices.UnmanagedType.ByVa lTStr,
SizeConst:=3)> Public RecType As Char()
<VBFixedString(6),
System.Runtime.InteropServices.MarshalAs
(System.Runtime.InteropServices.UnmanagedType.ByVa lTStr,
SizeConst:=6)> Public GPNumber As Char()
<VBFixedString(10),
System.Runtime.InteropServices.MarshalAs
(System.Runtime.InteropServices.UnmanagedType.ByVa lTStr,
SizeConst:=10)> Public GrantNumber As Char()
<VBFixedString(5),
System.Runtime.InteropServices.MarshalAs
(System.Runtime.InteropServices.UnmanagedType.ByVa lTStr,
SizeConst:=5)> Public VestOrder As Char()
<VBFixedString(10),
System.Runtime.InteropServices.MarshalAs
(System.Runtime.InteropServices.UnmanagedType.ByVa lTStr,
SizeConst:=10)> Public ExerNum As Char()
<VBFixedString(4),
System.Runtime.InteropServices.MarshalAs
(System.Runtime.InteropServices.UnmanagedType.ByVa lTStr,
SizeConst:=4)> Public Version As Char()
End Structure

<StructLayout(LayoutKind.Sequential)> _
Private Structure tDataStruct
Dim tSort As tSortKey
<VBFixedString(1141),
System.Runtime.InteropServices.MarshalAs
(System.Runtime.InteropServices.UnmanagedType.ByVa lTStr,
SizeConst:=1141)> Public sData As Char()
End Structure

Then I'm trying to use this code:

Dim p_objTarget As New IntPtr

p_objTarget = Marshal.AllocHGlobal(Marshal.SizeOf
(tRecord.GetType))
Marshal.StructureToPtr(tRecord, p_objTarget, True)
Call CopyMemory(p_objTarget, sRecordString,
Marshal.SizeOf(sRecordString))
Marshal.PtrToStructure(p_objTarget, tRecord)
Marshal.FreeHGlobal(p_objTarget)
I'm getting the following error:

Type tDataStruct can not be marshaled as an unmanaged
structure; no meaningful size or offset can be computed.

Please, anyone let me know what I'm doing wrong.

Thank you. YK

Jul 21 '05 #1
0 2153

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

Similar topics

0
by: Kurt Ng | last post by:
Need help quick!!! Am really stuck on this problem! I have a C dll, and it uses a nested struct. (see below) The struct has 2 layers of nested structs. The first field in the first struct is...
6
by: Angel | last post by:
I'm exporting (with DllImport) a C-style function with this syntax: int z9indqry (4_PARM *parm); 4_PARM is a structure declared in a proprietary header file that cannot be included in my...
3
by: Angel | last post by:
Hello again (and again, and again...) I think I'm getting closer to solving my initial problem of calling unmanaged code. I managed to call the functions with user-defined structs w/o getting any...
3
by: Rudy Velthuis | last post by:
Hello, Does anyone know how to create a struct that will marshal to the following C++ struct A, containing an array of the user defined String10 type: struct String10 { char SLen; char S;
0
by: Jeff | last post by:
Hi guys Mattias, thanx for answering my last question Well, I'm struggling with marshaling a struct that has **ptr to an array of arrays of struct. Why? I'm stuck with it 1. I need to know...
0
by: Mo | last post by:
I am having problem with marshaling struct in C#. //the original C++ struct typedef struct _tagHHP_DECODE_MSG { DWORD dwStructSize; // Size of decode structure. TCHAR ...
7
by: Mo | last post by:
I am having problem with marshaling struct in C#. //the original C++ struct typedef struct _tagHHP_DECODE_MSG { DWORD dwStructSize; // Size of decode structure. TCHAR ...
6
by: erdem | last post by:
hi all, i guess this question had been asked many times but i couldnt find a way how can we generate a struct with managed code with fixed size i mean struct easy {
4
by: taskswap | last post by:
I'm converting an application that relies heavily on a binary network protocol. Within this protocol are a lot of byte arrays of character data, like: public unsafe struct MsgAddEntry {...
5
by: michelqa | last post by:
Hi, I need to call a lot of different native SendMessage to retreive informations from non managed application. Some win32 messages use struct pointer for lparam....how to create and...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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...

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.