473,398 Members | 2,403 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,398 software developers and data experts.

Error using structs in calling unmanaged dll

I don't understand the following error I'm getting when I call the DoOpen
function of my unmanaged dll. Can someone explain please

[DllImport(DllName, CharSet=charset)]
public static extern int DoOpen(ref sRDetails RDetails);

"An unhandled exception of type 'System.TypeLoadException' occurred in
mmonitor.dll
Additional information: Can not marshal field ChDetails of type sRDetails:
This type can not be marshaled as a structure field."

[StructLayout(LayoutKind.Sequential)]
public struct sRDetails
{
public int UniqueID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXSTR_SNAME)]
public string SName;
public sTM TStamp;
public int ChEntries;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_CH)]
public sChDetails[] ChDetails;
}

[StructLayout(LayoutKind.Sequential)]
public struct sChDetails
{
public sHCode HCode;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXSTR_CH_NAME)]
public string ChName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXSTR_UNITS)]
public string Units1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXSTR_UNITS)]
public string Units2;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXSTR_HLLIMIT)]
public string HLLimit;
public float Value;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXSTR_TRSTATE)]
public string TrState;
}
Nov 16 '05 #1
1 1324
I don't understand the following error I'm getting when I call the DoOpen
function of my unmanaged dll. Can someone explain please


The marshaler doesn't support struct arrays nested inside another
struct.

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 16 '05 #2

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

Similar topics

26
by: codymanix | last post by:
Last night I had several thought about RAII and want to discuss a bit. Why doesn't CSharp support destructors in structs? Wouldn't that make RAII possible like in C++? When the struct goes out of...
7
by: Willem van Rumpt | last post by:
Hi all, coming from an unmanaged programming background, I took my time to sort out the IDisposable and finalizer patterns. Just when I thought I had it all conceptually neatly arranged, the...
3
by: B Vidyadhar Joshi | last post by:
I was writing an Bluetooth Application which makes calls to Windows APIs. I feel I'm doing something wrong with the structure. Could somebody help me? The code that I'm using is pasted below: ...
47
by: Bonj | last post by:
I downloaded the gzlib library from zlib in order to do compression. (http://www.gzip.org/zlib) The prototype of the compression function seems to be int compress (Bytef *dest, uLongf *destLen,...
8
by: Mas L via DotNetMonster.com | last post by:
Hi, I have a c++ source code which I can compile to be a DLL (in VS.NET 2003). And I need to use it in a C# program. After I compiled/build the C++ code to a DLL, I add it as a Reference in my...
7
by: Gustavo L. Fabro | last post by:
Greetings! Some classes that once compiled without problems on VS 2003 have now problems on VS 2005 Beta 1. I'm talking about a __nogc class that is exported with __declspec(dllexport). The...
61
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch...
6
by: guxu | last post by:
I have a managed C++ code which calls some methods in unmanaged C++ DLL. In my unmanaged DLL, I have a PROTECTED virutal function in a base class and derived class has a PRIVATE function which...
6
by: DaTurk | last post by:
Hi, I'm coding a layer into my application using CLI, between a unmanaged and a c# layer. So, I have to marshal some unmanaged c++ structures to structures usable in c#. My solution was to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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
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,...

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.