I'm a bit of a newbie to Pinvoke.
I have a large project that calls makes a call to a DLL called vtmail.dll
. It worked fine in .Net 3.5 but on upgrading to .NET 4.0 I am getting a PinvokeStackImbalance
exception
The calling code is a bit like this:
VTMail vtMail = new VTMail();
ec = vtMail.SendMail("servername",
false,
"",
"",
"Subject",
"Sender Name",
"sender@mydomain.com",
"",
"sendto@theirdomain.com",
"reply@mydomain.com,
"Description",
"foldername",
false,
25);
Checking the declaration in vtmail.dll is this:
public int SendMail(string mailServer, bool login, string userName,
string password, string subject, string fromName,
string fromAddress, string toName, string toAddress,
string replyToAddress, string bodyText, string folderToSend,
bool encrypt, long smtpPortNo);
I've searched around about this and it seems to be a known .Net 4.0 issue. Responses have always suggested adding CallingConvention=CallingConvention.Cdecl
to the DllImport
statement, but this particular call doesn't have a DllImport
statement, the dll is just added as a reference to the project in Visual Studio and is thus available.
How can I fix this?