3
Answers

Delphi DLL in C#

Dave

Dave

19y
5.4k
1
Hi, I have a Delphi 6 DLL that I need to run from C#.Net 2.0. I have some problems with it though. Here Goes: The Delphi Decalration is : function M_Login(ip : PChar; port : LongInt; uci : PChar; vol : PChar; pass : PChar; user : PChar) : LongInt; stdCall; And the C# Declaration is : [DllImport("iMSMAPI.DLL", CallingConvention = CallingConvention.StdCall, CharSet=CharSet.Ansi)] private static extern Int64 M_Login(string ip, Int64 port, string uci, string vol, string pass, string user); This gives me an AccessViolationException at RunTime when I call M_Login. I can Change the Delphi Declaration to expect Strings instead of PChars, this avoids the AccessViolationError, but this causes the values passed to the Delphi DLL to be incorrect. i.e. contain characters that the C# Application did not pass. I passed the value "127.0.0.1" as the ip parameter in C# and when I inspected the ip parameter in Delphi it was '1'#0'2'#0'7'#0'.'#0'0' . Can anyone help. Thanks in Advance, Dave Shaw
Answers (3)