TurboActivate PInvoke Error in .NET 4Solved

I'm in the process of converting my application to .NET 4 and I'm running into a problem with TurboActivate.(I'm converting so I can use the new parallel libraries.)

This problem can be duplicated using the VB sample in the TurboActivate 2.7 SDK.

- Open up the VB Sample- Change the framework to .NET 4- Copy the TurboActivate DLL into the Debug Folder- Set the Target CPU to x86

And you get this error when you try and run the sample:"A call to PInvoke function 'VB.NET!VB.NET.TurboActivate+Native::IsActivated' 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."

On the 'Select Case' line of this function:

Public Shared Function IsActivated() As Boolean Select Case Native.IsActivated(TurboActivate.VersionGUID)' removed extra lines Case 0 Return True End Select Return False End Function

, edited

Thanks for reporting this, I'll look into it.

The problem is that .NET 2.0+ assumes the calling convention is Cdecl, while .NET 4.0 does not. We'll have the example code fixed in TurboActivate 2.8. But to fix it now add "CallingConvention:=CallingConvention.Cdecl" to each of the function definitions.

For instance, instead of this:

<DllImport("TurboActivate.dll", CharSet:=CharSet.Unicode)> _Public Shared Function IsActivated(ByVal versionGUID As String) As IntegerEnd Function

You have this:

<DllImport("TurboActivate.dll", CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Cdecl)> _Public Shared Function IsActivated(ByVal versionGUID As String) As IntegerEnd Function

Thanks for finding this!

TurboActivate 2.8 is out with a number of fixes and improvements. Plus this bug is fixed for .NET 4 apps. Thanks again for spotting it.

Thanks. That fixed it.