Did P/Invoke environment change in .NET 4.0?

前端 未结 4 2443
心在旅途
心在旅途 2021-02-19 15:17

I\'ve started upgrading a .NET 2.0 WinForms application to .NET 4.0. Well, OK, the upgrade process was just a matter of switching platform target, but making it actually work.

相关标签:
4条回答
  • 2021-02-19 15:48

    Boolean is a one byte type on Delphi. So changing them must be with a one byte type

    0 讨论(0)
  • 2021-02-19 15:58

    Appears that this is a problem with the Calling Convention property in the DllImport attribute. Should be Cdecl not the default StdCall. I had this problem when migrating from 2.0 to 4.0 and running in VS2010. See article here. http://codenition.blogspot.com/2010/05/pinvokestackimbalance-in-net-40i-beg.html

    0 讨论(0)
  • 2021-02-19 15:59

    I see a similar problem with a Delphi dll: social_msdn
    I have noticed that my library compiled with FreePascal (instead of Delphi) works even within VS2010 without any problems. Therefore I don't know if Delphi, the .NET4 debugger or the combination is the reason for the trouble.

    There is some evidence that memory allocated during dll start-up (e.g. in the initialization section) is affected by the memory corruption.

    0 讨论(0)
  • 2021-02-19 16:01

    It appears to be a bug in the Visual Studio 2010 debugger. It seems to be clobbering memory that doesn't belong to it. All of the problems I've observed (all of which can be reproduced reliably) disappear completely if I run the application directly, instead of through Visual Studio 2010.

    The bug is actually in the Managed Debug Assistant. If you turn it off completely (set HKLM\Software\Microsoft.NETFramework\MDA = "0"), the problem goes away. But of course you lose some debugging capability by doing so.

    0 讨论(0)
提交回复
热议问题