Question about NetFx40_PInvokeStackResilience RRS feed

  • Question

  • I wrote a .net 4.0 C# WPF program which PInvokes a C++ dll. The calling convention of C++ dll function is not specified so it is by default __cdecl. I did not configure the NetFx40_PInvokeStackResilience option either. According to following article


    Platform invoke

    To improve performance in interoperability with unmanaged code, incorrect calling conventions in a platform invoke now cause the application to fail. In previous versions, the marshaling layer resolved these errors up the stack.

    Debugging your applications in Microsoft Visual Studio 2010 will alert you to these errors so you can correct them.

    If you have binaries that cannot be updated, you can include the <NetFx40_PInvokeStackResilience> element in your application's configuration file to enable calling errors to be resolved up the stack as in earlier versions. However, this may affect the performance of your application.

    which is located at

    I should have a Stack imbalance, i.e. my stack will grow by each call. However by debugging I find that the ESP register value of the C# program does not change at all after a PInvoke return, i.e. the stack does not grow in effect(in fact balanced!). If this is true, why is there such a confusing documentation message there? Could anybody give a clear answer? Thanks in advance!

    Friday, February 17, 2012 8:43 AM

All replies

  • Btw, my computer environment is Windows 7 Ultimate, CLR version:

    Versions installed on the machine:

    • Edited by Shigang Friday, February 17, 2012 8:59 AM
    Friday, February 17, 2012 8:58 AM