Skip to content

Delphi DLL in C#

Dave

Asked Oct 29, 2005, 8:35 AM EDT3 answers
Share
LinkedInX
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

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mahesh Chand
    0
    Is it a COM DLL? If its a COM DLL, its pretty easy using DLLImport and it will create a Wrapper around DLL for .NET and then it can be used same as any other .NET DLL.

    If it is not a COM DLL, then you will have to import dll in your code. There are some samples on C# Corner. Search www.c-sharpcorner.com for importing DLL in C# or something.
    0
  • 0
    Thanks, I have now overcome this problem, however. I am now getting a BroadcastEventWindow.2.0.0.0.33 when I close my application. I am then getting RunTime Error 217 once then getting RunTime Error 216 followed by 'The Memory Could not be "Read"' message in a Continuous Loop until I Kill my Application. Any Ideas? Thanks. Dave
    0
  • 0
    Hi, I have fixed this also, nothing a good nights sleep can't cure. :-) The cause was that I was passing strings to the Delphi DLL, so I was using ShareMem Unit. But it was not the first unit in the Uses Declaration. That will teach me for deleting the useful comments provided by Delphi. Doh! :-) Thanks.
    0