473,795 Members | 2,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Marshaling a C++ two-dimensional fixed length char array as a structure member

6 New Member
Hallo everyone.

I am trying to call an unmanaged C++ function, that has a structure as an input parameter.
The structure is defined in the header file like this:

Expand|Select|Wrap|Line Numbers
  1. struct MyStruct
  2. {
  3.     int     siOrder;
  4.     char     aaszNames[6][25];
  5.     int     siId[6];
  6.     int     siTones[6];        
  7. };
I've defined the managed structure as following:

Expand|Select|Wrap|Line Numbers
  1. <StructLayoutAttribute(LayoutKind.Sequential, CharSet:=CharSet.[Ansi])> _
  2. Public Structure MyStruct
  3.     Public siOrder As Integer
  4.  
  5.     <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=150)> _
  6.     Public aaszNames As String
  7.  
  8.     <MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst:=6, ArraySubType:=UnmanagedType.I4)> _
  9.     Public siId() As Integer
  10.  
  11.     <MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst:=6, ArraySubType:=UnmanagedType.I4)> _
  12.     Public siTones() As Integer
  13. End Structure
The C++ dll writes to a log file when a function is called. From this log I can see that the structure cannot be resolved.

My issues are the following:

a) Marshal.SizeOf( MyStruct) is computed as 204, but as I can see, the size seems to be: 4 + 150 + 6*4 + 6*4 = 202 bytes. What are these two extra bytes, and where are they supposed to be padded?

b) How should I populate the aaszNames field? The C++ expects 6 rows of 25 character long strings, but my individual values are of less length (eg "John", "Robert", etc). How should I concatenate the string?

Could anyone give me a hint about these issues?
Feb 12 '10 #1
6 2001
CroCrew
564 Recognized Expert Contributor
Is this a C++ or VB question? If it a C++ question you would get a faster reply to your question if it were posted in the C++ section and not the VB section.

Hope you get your answer,
CroCrew~
Feb 12 '10 #2
TTheot
6 New Member
Well, I could also try the C++ section... ;)
Feb 12 '10 #3
CroCrew
564 Recognized Expert Contributor
Lets see if we can get this moved to the C++ section.

Good Luck in getting your answer,
CroCrew~
Feb 12 '10 #4
TTheot
6 New Member
Thanx CroCrew :)

Hoping for some hints myself..
Feb 12 '10 #5
tlhintoq
3,525 Recognized Expert Specialist
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Feb 12 '10 #6
Curtis Rutland
3,256 Recognized Expert Specialist
Thread moved. Hope you find your answers.
Feb 12 '10 #7

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

Similar topics

0
3788
by: S Mulgund | last post by:
I have some legacy data that I want to convert to XML. I've designed a schema to represent the data in XML form, and I'm trying to figure out how best to perform the raw->XML conversion. The Java web services tutorial shows how to use Transformers and SAXSource objects to perform the conversion in a memory-efficient way, but it requires that I take responsibility for adherence to the schema myself in how I generate the XML output. So I...
0
1894
by: Ash | last post by:
Hi, Has anyone ever tried using "COM marshaling" for cross- process communication? In particular, I am interested in cross-process marshaling between Managed Server and Unmanaged Client. There seems to be very little documentation/examples on this. I have a "Service" that needs to have a COM
4
11711
by: Vadym Stetsyak | last post by:
Hi there!!! I'm looking for any resources on the subject. Any help will be appreciated! -- Vadym Stetsyak ICQ 161730125 He, who commands the past - commands the future
5
96499
by: VM | last post by:
What's marshalling? I've had to use it extensively for a project but I don't know what it means. I tried to look for a definition in the Internet but I couldn't find anything that would explain what it is. Is converting a C-style struct to a C# class (or struct) marshalling? And what about the function exports? Are those Marshalling too? Thanks for your help and thanks for helping me with the Dll exports (the several messages I posted in...
1
2483
by: Nadav | last post by:
Hi I am about to write a performance crutial system, I am considering writing this system based on native COM or unmanaged C++ exposed as CLI, Now, I Wonder... does exposing a native code through CLI ( using a mixed mode DLL ) have any performance penalty? consider one Native C++ CLI assembly calling a methos od another CLI Native C++ Assembly, will there be any marshaling penalty, will there be any penelty at-all? is it possible to pass a...
4
3149
by: MSDousti | last post by:
Hi all, I read some Q&As in the Net, discussing Marshalization of nested structs in C# (or VB.NET). Some guys stated that .NET framework does not support this feature yet. Are they right? BTW, by nested structs I mean structures such as this:
1
2680
by: Bill Medland | last post by:
I am trying to do some P/Invoke custom marshaling and am looking for a little help on custom marshaling a value type. I am working based on Kate Gregory's "Arranging Custom Marshaling With P/Invoke", which is unfortunately in C++ with managed extensions; I am working in C#. As with Kate's example I want to marshal from a System.DateTime to a proprietary format. However I cannot figure out how to tell the system to box the DateTime. ...
0
948
by: chowsaikeet | last post by:
Dear All, I have trouble doing marshaling for polymorphism. Please look at the code below: //C++ code, sample.dll Class A {
0
1880
by: jpogorman | last post by:
Hello, I am trying to get c# custom marshaling working in a particular scenario but it does not appear to be working or not jumping into my marshaling class when I try to debug it. I am try to implement a performance improvement in the transfer of thousands of objects (ClientInfoDescriptor) over a remote call. The objects all have a model object (IDataDrivenModel) to describe them but there may only two or three model objects in total. These...
5
5237
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 marshaling the struct to be able to use it in sendmessage... Here is an example LM_GETITEM: http://msdn.microsoft.com/en-us/library/bb760720(VS.85).aspx
0
10443
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...
1
10165
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9044
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
7543
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
6783
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
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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 we have to send another system
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.