|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
|
|
|
Re: Returning structures by value in .NET with P/InvokeDavid 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 > 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 |
|
|
Re: Returning structures by value in .NET with P/Invoke> 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. I'm not suggesting that SWIG attempt to generate code for this; I just wanted to complete the picture on this issue. If I may correct a misconception in your comment: while there may be a bug in the CLR, the issue I talk about here is entirely on the C++ side (how would the CLR know if my C++ class has a constructor or not?). And IIRC, there is no problem with passing structs by value--only with returning them. I just put a bug report on Microsoft Connect: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?Fe edbackID=345096 But in my experience, Microsoft fixes things rather slowly. ------------------------------------------------------------------------- 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 |
| Free Forum Powered by Nabble | Forum Help |