473,378 Members | 1,369 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,378 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 2241
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JH | last post by:
Can anyone show me what VB .NET language is required to send a structure with an array to a unmanaged code function that needs the structure elements in contiguous memory locations? I've tried some...
7
by: savage | last post by:
hey all i need to convert an unmanaged c++ dll and header to c#, ive done the header structures but having problems with pinvoke signatures method 1: typedef int (_stdcall *pOmniConnect) (char...
5
by: Carlos Guzmán Álvarez | last post by:
Hello: I'm trying to execute a function of a unmanaged dll using PInvoke, i have definied the function as: public static extern int isc_dsql_prepare( int status_vector, ref int...
2
by: nicolasr | last post by:
Hi, I need to PInvoke the ExtCreateRegion API. How do I declare the structures used by it and the function itself in C#? The original declarations are: typedef struct _RGNDATAHEADER {...
2
by: John Smith | last post by:
Hello :) I have a DLL file written in C where one function accepts an array of structures as input paramter and pointer to length integer. This function will fill up the array and specify the...
3
by: Brett Robichaud | last post by:
I have created a simple background thread to make one pinvoke call into a DLL I've created. My Winforms app spawns the thread in the form load event then go about it's business. The problem is...
5
by: vertigo | last post by:
Hello I use some win 32 API function for example: HANDLE CreateFile( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD...
2
by: steve | last post by:
Hi all, I want to understand more about how the pinvoke pinning process works. I'm writing some code that calls DeviceIoControl. DeviceIoControl provides a generic interface to device drivers....
6
by: gregarican | last post by:
I am trying to port a legacy CTI application written in another programming language to C# 2005. From my initial research into it I see I can utilize the DllImport method to tap into the DLL file...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.