471,306 Members | 1,249 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

PInvoke - Structures

[StructLayout(LayoutKind.Sequential)]
struct MyStruct
{
public int Number;
}

[StructLayout(LayoutKind.Sequential)]
struct MyStruct
{
private int mNumber;
public int Number
{
get {
return mNumber;
}
set {
mNumber = value;
}
}
}

For PInvoke calls, are the two structures above interchangeable? If a
structure is defined as the first MyStruct, can I use an instance of the 2nd
MyStruct?

Thanks,
Mythran

Feb 22 '06 #1
6 2139
"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
For PInvoke calls, are the two structures above interchangeable? If a
structure is defined as the first MyStruct, can I use an instance of the
2nd MyStruct?


I dunno, give it a try and see. You'll have your answer in a minute or so.

Michael
Feb 22 '06 #2

"Michael C" <no****@nospam.com> wrote in message
news:eg**************@TK2MSFTNGP14.phx.gbl...
"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
For PInvoke calls, are the two structures above interchangeable? If a
structure is defined as the first MyStruct, can I use an instance of the
2nd MyStruct?


I dunno, give it a try and see. You'll have your answer in a minute or so.

Michael


I did try and the results are...confusing :)

I created a struct for RECT and used properties instead of members. It
worked fine. When I put Console.WriteLine inside the getter for Left, the
returned value for the function I used returned an empty
structure...repeatedly.

<shrug>

Mythran

Feb 23 '06 #3
"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:eQ**************@TK2MSFTNGP14.phx.gbl...
I did try and the results are...confusing :)

I created a struct for RECT and used properties instead of members. It
worked fine. When I put Console.WriteLine inside the getter for Left, the
returned value for the function I used returned an empty
structure...repeatedly.
I don't quite get what you mean here?


<shrug>

Mythran

Feb 24 '06 #4

"Michael C" <no****@nospam.com> wrote in message
news:ei**************@TK2MSFTNGP15.phx.gbl...
"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:eQ**************@TK2MSFTNGP14.phx.gbl...
I did try and the results are...confusing :)

I created a struct for RECT and used properties instead of members. It
worked fine. When I put Console.WriteLine inside the getter for Left,
the returned value for the function I used returned an empty
structure...repeatedly.


I don't quite get what you mean here?


<shrug>

Mythran



I don't remember which api call I made, but it returns a code that you can
use to identify what the contents of RECT is. I set it up using the normal
RECT layout, and it worked fine (the return code was the code that said it
had data in it). When I changed to properties, it also worked fine. Once I
put in a Console.WriteLine inside the get {} part of the Left property, the
return code was the code the meant there was no data in the RECT structure
(the RECT was empty).

Mythran

Feb 24 '06 #5
Ok, I tried this (no code included, just letting ya know what I tried).

In my Left property for my struct that contains public properties instead of
public members, I put a Console.WriteLine("HERE"); after I set the private
member, mLeft. When I pass this structure to the API function, the
structure is returned (out parameter) with data in it. The
Console.WriteLine() call is never called though (no "HERE" on console
window). The Left value is set though. It could be that it just places the
values in memory at the locations of the first 4 members, I'd have to give
it a try and test it out. But it's not that important :)

Mythran

Feb 24 '06 #6
"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:ed**************@tk2msftngp13.phx.gbl...
Ok, I tried this (no code included, just letting ya know what I tried).

In my Left property for my struct that contains public properties instead
of public members, I put a Console.WriteLine("HERE"); after I set the
private member, mLeft. When I pass this structure to the API function,
the structure is returned (out parameter) with data in it. The
Console.WriteLine() call is never called though (no "HERE" on console
window). The Left value is set though. It could be that it just places
the values in memory at the locations of the first 4 members, I'd have to
give it a try and test it out. But it's not that important :)


That makes sense, it must be picking up the private variables still and
marshalling those.

Michael
Feb 25 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by savage | last post: by
5 posts views Thread by Carlos Guzmán Álvarez | last post: by
2 posts views Thread by nicolasr | last post: by
3 posts views Thread by Brett Robichaud | last post: by
5 posts views Thread by vertigo | last post: by
6 posts views Thread by gregarican | last post: by
reply views Thread by rosydwin | last post: by

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.