473,671 Members | 2,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Marshaling Multi-Dimensional Arrays

I have a dll that is expecting a 3x3 array which I'm am using DllImport to access. In addition, this array is located in a struct that is getting passed. I'm having problems that I think are located somewhere in how I'm marshaling it. Any input would be appreciated.
(examples are shortened for clarity, let me know if something more complete would be useful

/*C code*
typedef float RotMtxType[3][3]
typedef struct
double ccNum
RotMtxType ccuGCCtoLNEDrot Mtx;
extern int ccuInitStateStr ucture
CCUStateStruct *ccuStatePtr)

//C# Cod
[StructLayout(La youtKind.Sequen tial)
public struct CCUStateStruc
public double ccNum
[MarshalAs(Unman agedType.ByValA rray, SizeConst=9
public float [,] ccuGCCtoLNEDDro tMtx
elsewhere ..
ccuState.ccuGCC toLNEDDrotMtx = new float[3,3
...

[DllImport("CCU. dll")
public extern static int ccuInitStateStr ucture
[MarshalAs(Unman agedType.Struct )]ref CCUStateStruct ccuStatePtr)

I then get the error
Additional information: Can not marshal field ccuGCCtoLNEDrot Mtx of type CCUStateStruct: This type can not be marshaled as a structure field

Thanks much
To

Nov 16 '05 #1
2 8671
If you declare ccuGCCtoLNEDDro tMtx as a single dim array, does that work?
Could you add some property get/sets to expose the single dim array as a two
dim array?

"Thomas Kent" <te*****@commun ity.nospam> wrote in message
news:14******** *************** ***********@mic rosoft.com...
I have a dll that is expecting a 3x3 array which I'm am using DllImport to access. In addition, this array is located in a struct that is getting
passed. I'm having problems that I think are located somewhere in how I'm
marshaling it. Any input would be appreciated. (examples are shortened for clarity, let me know if something more complete would be useful)
/*C code*/
typedef float RotMtxType[3][3];
typedef struct {
double ccNum;
RotMtxType ccuGCCtoLNEDrot Mtx;
}

extern int ccuInitStateStr ucture(
CCUStateStruct *ccuStatePtr);

//C# Code
[StructLayout(La youtKind.Sequen tial)]
public struct CCUStateStruct
{

public double ccNum;
[MarshalAs(Unman agedType.ByValA rray, SizeConst=9]
public float [,] ccuGCCtoLNEDDro tMtx;
}

elsewhere ...
ccuState.ccuGCC toLNEDDrotMtx = new float[3,3]
...

[DllImport("CCU. dll")]
public extern static int ccuInitStateStr ucture (
[MarshalAs(Unman agedType.Struct )]ref CCUStateStruct ccuStatePtr);
I then get the error:
Additional information: Can not marshal field ccuGCCtoLNEDrot Mtx of type CCUStateStruct: This type can not be marshaled as a structure field.

Thanks much!
Tom

Nov 16 '05 #2
Hi Tom,

Based on my understanding, you want to P/invoke a Structure with a field of
Multi-Dimensional array.

For your issue, you may use single dimensional C# array to store the value
and marshal to your dll. Do like this:

[StructLayout(La youtKind.Sequen tial)]
public struct CCUStateStruct
{
public double ccNum;
[MarshalAs(Unman agedType.ByValA rray, SizeConst=9)]
public float [] ccuGCCtoLNEDDro tMtx;
}

Then, you can use it like:
try
{
CCUStateStruct obj=new CCUStateStruct( );
obj.ccNum=0.0;
float [] test=new float[9];

obj.ccuGCCtoLNE DDrotMtx=test;
ccuInitStateStr ucture(ref obj);
}
catch(Exception ex)
{
MessageBox.Show (ex.Message);
}

I have tested this on my machine, it works well.

=============== =============== =====
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #3

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

Similar topics

0
1884
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
3
2661
by: Nikolay Petrov | last post by:
Guys, please help. I am trying to make this work from at least 4 months. I am new to programming and some things are difficult to me, but I really need to make my project work. I can't find anything helpfull in internet for 4 months ;-( . Please someone who is more expirenced help me. I am trying to use the Terminal Server APIs There is as an API function WTSEnumerateSessions, which returns a WTS_SESSION_INFO custom structure n times....
4
11698
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
3
1312
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example below... --
5
96483
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
2473
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
3139
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:
8
1379
by: Just Me | last post by:
I have SendMessage declared with the last two parameters as ByVal IntPtr I need to call it with an Integer value and a Byte array pointer. The Integer is while the Byte array is I could probably figure how to do the pointer using Marshal.AllocHGlobal , Marshal.StructureToPtr, ... If that's the simplest way to do it. But is it? Also, if the integer value was zero I'd use IntPtr.Zero, but it's not zero -
1
2672
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
1871
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...
0
8473
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
8390
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
8911
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
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8667
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
7428
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
6222
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
5692
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
4222
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.