Here is the signature of the DLL function I am trying to import
typedef char*(*DLLFUNC_Encrypt)(const char*, unsigned int, unsigned int&);
Here is my C# code
[DllImport("AuthCrypto.dll", EntryPoint = "Encrypt")]
public static extern IntPtr Encrypt(IntPtr data, int size, ref int mode);
public static string EncryptData(string data)
{
int mode = 5;
IntPtr dataIntPtr = Marshal.StringToHGlobalAnsi(data);
IntPtr data_enc = CryptoAPI.Encrypt(dataIntPtr, data.Length, ref mode);
return Marshal.PtrToStringAnsi(data_enc);
}
Here is my exception:
A call to PInvoke function 'CryptoAPI::Encrypt' 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.