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.
StringBuilder. Also, what does the Delphi code do? How do you know how big a buffer to allocate in theStringBuilder? What does theC500pcharactually do? Presumably it copies text to the buffer passed to it. How much text? What is the return value. Seeing the Delphi code that calls the DLL would also help hugely. If I could see both the Delphi code to call the DLL and the full C# calling code then I'm sure I can find the error. Please do this as an edit to the question. - David Heffernan