Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi Dlls in C#

Status
Not open for further replies.

viper1777

Programmer
Dec 3, 2003
21
0
0
GB
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 :
Code:
function M_Login(ip : PChar; port : LongInt; uci : PChar; vol : PChar; pass : PChar; user : PChar) : LongInt; stdCall;
And the C# Declaration is :
Code:
[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, I have also posted in the C# Forum, incase it is a C# issue.

Thanx!

Dave Shaw
Nothing is Impossible, it is just something I haven't got round to doing. - Me
History admires the wise, but elevates the brave. - Edmund Morris
 
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?



Thanx!

Dave Shaw
Nothing is Impossible, it is just something I haven't got round to doing. - Me
History admires the wise, but elevates the brave. - Edmund Morris
 
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.

Thanx!

Dave Shaw
Nothing is Impossible, it is just something I haven't got round to doing. - Me
History admires the wise, but elevates the brave. - Edmund Morris
 
I understand your problem, similar problem occurred to me too ... fortunatelly i did not delete the useful comments about "ShareMem" [smile2].

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top