I am getting this error message after importing an AddIn to and started comiling the code with VS 2015: Framework: VS 2015 and ArcGIS 10.4.1 PInvokeStackImbalance occurred. Message: Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in 'C:\Program Files (x86)\ArcGIS\Desktop10.4\bin\ArcMap.exe'. Additional information: A call to PInvoke function 'ESRI.ArcGIS.ADF.Local!ESRI.ArcGIS.ADF.Native::memcpy' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. PInvokeStackImbalance MDA
In this articleThe The Note The SymptomsAn application encounters an access violation or memory corruption when making or following a platform invoke call. CauseThe managed signature of the platform invoke call might not match the unmanaged signature of the method being called. This mismatch can be caused by the managed signature not declaring the correct number of parameters or not specifying the appropriate size for the parameters. The MDA can also activate because the calling convention, possibly specified by the DllImportAttribute attribute, does not match the unmanaged calling convention. ResolutionReview the managed platform invoke signature and calling convention to confirm it matches the signature and calling convention of the native target. Try explicitly specifying the calling convention on both the managed and unmanaged sides. It is also possible, although not as likely, that the unmanaged function unbalanced the stack for some other reason, such as a bug in the unmanaged compiler. Effect on the RuntimeForces all platform invoke calls to take the nonoptimized path in the CLR. OutputThe MDA message gives the name of the platform invoke method call that is causing the stack imbalance. A sample message of a platform invoke call on method A call to PInvoke function 'SampleMethod' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature. Configuration
See also
Collaborate with us on GitHub The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. A call to PInvoke function CopyMemory; has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature. here is my code Private Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (ByRef Destination As Object, ByRef Source As Object, ByVal numbytes As Long) Public Function BytesToDouble(ByVal TheArray() As Byte) As Double 'This function combines array of 8 bytes to a Double number - Format Little Endian Dim TempLong As Double Call CopyMemory(TempLong, TheArray(LBound(TheArray)), 8) BytesToDouble = TempLong End Function This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL) |