none
Question for 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

    http://msdn.microsoft.com/en-us/library/ff361650.aspx

    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, i.e. the stack does not grow in effect. So does this mean that this is not a problem any more?
    (I ask this question because I suspect one problem I encountered is due to this reason, however now it seems the so said "Stack imbalance" here does not make any difference?)

    My C# program:
    private void Button_Click(object sender, RoutedEventArgs e)
            {
                for (int i = 0; ; i++)
                {
                    int a = 10;
                    int b = 20;

                    //Here I observe the ESP register, however it never changes.
                    int c = TestWin32DllVS2010.fnTestWin32DllVS2010(a, b);
                    this.Result.Text = c.ToString();
                }
            }

    public class TestWin32DllVS2010
        {
           const string strAssemblyName = "TestWin32DllVS2010.dll";
            [DllImport(strAssemblyName, EntryPoint = "?fnTestWin32DllVS2010@@YAHHH@Z", SetLastError = true)]
            public static extern System.Int32 fnTestWin32DllVS2010(System.Int32 a, System.Int32 b);
        }

    My C++ dll code:

    __declspec(dllexport) int fnTestWin32DllVS2010(int a, int b)
    {
     int c=a+b;
     return c;
    }

    Friday, February 10, 2012 3:17 AM