I’ve seen some topics about my issue, but they weren’t so clear to help me.
My problem is: I have a Delphi 7 Application that calls an external dll, from a third-part (wich I have no access to source). I’m trying to convert the Delphi code to C# (.NET 2.0).
Here is the delphi code to call the dll:
function C500pchar(Comando : pchar):Integer; stdcall; external 'c50032.dll' name 'C500';
Here is my C# code to call the same dll:
[DllImport("C50032.DLL", CallingConvention = CallingConvention.StdCall, EntryPoint = "C500")]
static extern int C500pchar(StringBuilder Comando);
This C# code is working fine when I run it from Visual Studio 2005, but when I try to run the exe file, it crashes when the application calls the Method C500pchar. I tried to copy all files from Release and Debug folders and even run the exe from the folders, but it just work when I’m running from VS.
Am I doing anything wrong?
EDIT: I’m working on Windows 7 and facing this issue. But I’ve tried running on Windows XP SP3 and worked fine.
Your project runs in 32bit mode in visual studio, but in 64 bits mode when run directly. You must change the project settings so it runs in x86 instead of any cpu.