bugDotGNU Portable.NET - Bugs: bug #20354, Problems with pinvoke declared to...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #20354: Problems with pinvoke declared to return struct

Submitter:  Radek Polak <radekp>
Submitted:  Thu 05 Jul 2007 07:28:48 AM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Invalid
Privacy:  Public Assigned to:  None
Open/Closed:  Closed

Thu 05 Jul 2007 12:15:55 PM UTC, comment #1: 

It seems that the code works only on windows. On linux (even with mono) it fails because of different calling conventions.

[13:47] <klausT|work> the pinvoked function doesn't return a struct
[13:51] <radekp> yep
[13:51] <klausT|work> does the function return an int or a boolean?
[13:51] <radekp> int
[13:52] <klausT|work> so you declared the return type in C# as int too?
[13:52] <radekp> if i declare return type as int it works
[13:53] <radekp> but if i declare it with return type as struct it fails
[13:53] <klausT|work> yes, of course it fails
[13:53] <radekp> on .NET it works on pnet no
[13:53] <klausT|work> because the signatures don't match
[13:54] <radekp> and on .NET they match?
[13:54] <klausT|work> on Windows you have usually the WINAPI/STDCALL calling convention
[13:55] <klausT|work> the struct return value is handled different there
[13:55] <klausT|work> the callee pops the args from the stack and pushes the return value
[13:57] <klausT|work> o no additional arg for the return value
[13:59] <radekp> so the conclusion is that the pinvoking is badly declared and will work on windows only?
[14:01] <klausT|work> yes, if the c function returns an int the return value in C# has to be int too

Radek Polak <radekp>
Group Member
Thu 05 Jul 2007 07:28:48 AM UTC, original submission:  

Hi,
in the attached sample we call Fn() via pinvoke.

If the pinvoke is declared to return int everything works.
If the pinvoke is declared to return struct with one int field, the arguments are shifted.

Both declarations should work. This was tested with jit coder.

Radek Polak <radekp>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #13251:  pinvoke.tar.gz added by radekp (4KiB - application/gzip)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by radekp (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-07-05 radekp StatusNone Invalid
        Open/ClosedOpen Closed
    2007-07-05 radekp Attached File- Added pinvoke.tar.gz, #13251

    Back to the top

    Powered by Savane 3.12