Re: Structure in CSharp
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Wed, 09 May 2007 21:42:30 -0700
On Wed, 09 May 2007 18:49:01 -0700, Yatin Patel <YatinPatel@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
[...]
This for some reason is not working for LocalPhoneNumber field in the above structure. It gives runtime error which is as below:
Cannot marshal field 'MyStruct' of type 'R_OMNI_LINK_MESSAGE': The type
definition of this field has layout information but has an invalid
managed/unmanaged type combination or is unmarshalable.
Well, you're beyond me at this point. :) I haven't done enough of what you're trying to do to consider myself very helpful on the matter.
Being ignorant's never stopped me from commenting in the past though, so I'll point out a few of things I noticed:
One is that your _myUnion struct doesn't look to me to be the same as the original struct you've specified. You've got as its first field a single byte "_messageType", but the original struct has a 255-byte array named "Data". In addition, you've instructed C# to marshal that single byte as a 255 element array. If I were the C# compiler, I might complain about something like that too. :)
Another thing is that the _olmSYSTEM_INFORMATION struct doesn't look like anything in your original struct definition. This may or may not be a problem, but I am left wondering how you got from the original struct definition you posted to the C# declaration you've also posted.
Finally, in the same way that your declaration in "_myUnion" for the "_messageType" field looks odd to me, so too does the declaration for "LocalPhoneNumber" in the "_olmSYSTEM_INFORMATION" struct. It's a byte, but you're telling C# it's an array of length 25.
I figure there's one of two possibilities: either this is actually how you're supposed to do it, and C# has some really weird syntax that I don't understand; or, it's not how you're supposed to do it, and you're supposed to declare types in C# that are at least roughly the same as the unmanaged type you're trying to get. Honestly, either one of those is possible for all I know. But you might want to think about the possibility that it's the latter that's causing you trouble. :)
Pete
.
- References:
- Re: Structure in CSharp
- From: Peter Duniho
- Re: Structure in CSharp
- From: Yatin Patel
- Re: Structure in CSharp
- Prev by Date: Re: Structure in CSharp
- Next by Date: Re: self-confidence of compiler
- Previous by thread: Re: Structure in CSharp
- Next by thread: How to set the publisher in the meta data?
- Index(es):
Relevant Pages
|