« Return to Thread: Re: Returning structures by value in .NET with P/Invoke

Re: Returning structures by value in .NET with P/Invoke

by wsfulton :: Rate this Message:

Reply to Author | View in Thread

David Piepgrass wrote:

> Maybe I'm the only one dealing with this issue, but I'll post it anyway
> for the record.
>
> I'd just like to add a new wrinkle to this old thread. It seems that if
> the structure you return has a constructor, then the C++ compiler
> decides to add 4 to the number at the end of the exported name, and thus
> the C++ and C# exported names match. See, in the example below I suggest
> declaring an alias in your .def file:
>
>    _CSharp_CreateSquareBox@16 = _CSharp_CreateSquareBox@12
>
> BUT if the Box structure is given a constructor, the C++ compiler will
> (or at least might) decide to use the name _CSharp_CreateSquareBox@16 in
> the first place. Consequently the line in the .def file is not only
> unnecessary but illegal and you get this linker output:
>  
> warning LNK4197: export '_CSharp_CreateSquareBox@16' specified multiple
> times; using first specification
> error LNK2001: unresolved external symbol _CSharp_CreateSquareBox@12
>
> Gee whiz, Microsoft does weird things. Also, when you give your
> structure a constructor, the C++ compiler will give you a warning
>
This all strikes me as a bug in the CLR. Maybe you discuss this on a
Microsoft .NET mailing list for confirmation and let us know the
outcome? It is nearly impossible to auto generate code for this kind of
weirdness and it would be nice to get support for pass by value into
swig. There isn't this kind of weirdness on Linux btw, I'm sure I got
this working a few years ago with mono and Linux, but never took it any
further as it doesn't work on the MS platform.

William

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

 « Return to Thread: Re: Returning structures by value in .NET with P/Invoke

LightInTheBox - Buy quality products at wholesale price