2
votes

I my c# app I am trying to call into a Delphi DLL build as 64bit. I keep getting an error stating "An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B". I am running on a Windows 7 64 bit machine and have my C# project set to Any CPU.

API call

[DllImport("Cipher.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.ThisCall)]
public static extern void Encrypt(StringBuilder szPlainText, StringBuilder  zCipherText);

Encrypt(plainString, encText);    

If the Delphi DLL was build as 32bit this call works fine. Any ideas?

1
ThisCall is wrong. Delphi doesn't do that. Use stdcall. - David Heffernan

1 Answers

4
votes

For some reason your app is not run as a 64-bit but rather a 32-bit process. If you need to do things like this, it's better to specify "x64" instead of "AnyCPU".