In my application I'm trying to invoke a function from an external DLL (this DLL is compiled in C++)

I have this code to declare the DLL function:
Code:
<DllImport("{DLLPATH}", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function functionName(<MarshalAs(UnmanagedType.VBByRefStr)> ByRef Name1 As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef Name2 As String) As Short
End Function
(where {DLLPATH} is the DLL file name)

then into my code I call the function with this:

Code:
functionName("String1","String2")
If I compile the code with .NET 2, it work perfectly; if I compile it with .NET 4 it guves me the following error:

A call to PInvoke function 'TestVB!TestVB.Form1::functionName' 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.
Can someone help me to make the code work in .NET 4??

Thank you in advance.