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

Accessing fields in a C structure via C#

Hi,

I'm using P/Invoke to call some C functions from a DLL.
My C function returns a pointer to a large C structure. I store this
returned pointer in an IntPtr C# variable. I would now like
to access the data in this structure.

What is the best way to do this? The structure is so large that I can't
lay it out as a C# struct. What else could I do?

Thanks,

Ted
Nov 15 '05 #1
2 1301
What is the best way to do this? The structure is so large that I can't
lay it out as a C# struct. What else could I do?


Really? I didn't know there was any size limitation on structs? So
exactly how large is it?

I guess you could use unsafe code, cast to a pointer of the
appropriate type and then use that to read/write members in the
struct.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #2
There is no limit on the struct size.

Your best bet is to post with the C++ function header. the framework.interop
newgroup is a good one to ask this sort of question on.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://weblogs.asp.net/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Ted Sung" <te**@intex.com> wrote in message
news:86**************************@posting.google.c om...
Hi,

I'm using P/Invoke to call some C functions from a DLL.
My C function returns a pointer to a large C structure. I store this
returned pointer in an IntPtr C# variable. I would now like
to access the data in this structure.

What is the best way to do this? The structure is so large that I can't
lay it out as a C# struct. What else could I do?

Thanks,

Ted

Nov 15 '05 #3

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

Similar topics

1
by: | last post by:
Is it possible to access the previous page's viewstate directly through the context object after a server.transfer. If so, how? The way i'm doing it is saving all needed items to a structure on...
1
by: | last post by:
Is it possible to access the previous page's viewstate directly through the context object after a server.transfer. If so, how? The way i'm doing it is saving all needed items to a structure on...
7
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a...
5
by: Andy | last post by:
I'm having trouble accessing an unmanaged long from a managed class in VC++.NET When I do, the contents of the variable seem to be mangled. If I access the same variable byte-by-byte, I get the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
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.