The Artima Developer Community
Sponsored Link

C# Answers Forum
use delphi dll in c#

3 replies on 1 page. Most recent reply: Apr 5, 2010 11:45 AM by Alex Kazanskiy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Erdos Andras

Posts: 1
Nickname: easoft
Registered: May, 2004

use delphi dll in c# Posted: May 20, 2004 5:58 AM
Reply to this message Reply
Advertisement
Hi

I want use dll (Delphi 7) in c#

example

delphi

procedure GetNev(s:PChar);export;
begin
ShowMessage(s) ;
end;
exports GetNev;


c#

[DllImport( "project1.dll", CallingConvention = CallingConvention.StdCall, CharSet=CharSet.Unicode )]
public static extern void GetNev(string s);

GetNev("hello");


problem:
Message is: */-/_:? (not "Hello")

what is tha problem???

Thanks Erdosa

erdos.andras@eduweb.hu


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: use delphi dll in c# Posted: Jun 4, 2004 8:13 AM
Reply to this message Reply
It might be that the string is double byte in C# and single in Delphi.

Another way to call Delphi code from C# is to use COM Automation. In that case you'll be using BSTRs which should also help to alleviate the double/single byte confusion.

Joe Cheng

Posts: 65
Nickname: jcheng
Registered: Oct, 2002

Re: use delphi dll in c# Posted: Jun 8, 2004 9:05 AM
Reply to this message Reply
If Matt's correct about the double/single byte conversion, I think you can fix it by just changing CharSet.Unicode to CharSet.Ansi.

Alex Kazanskiy

Posts: 1
Nickname: kazanskiy
Registered: Apr, 2010

Re: use delphi dll in c# Posted: Apr 5, 2010 11:45 AM
Reply to this message Reply
Delphi declaration should be

procedure GetNev(s:PChar);export; stdcall;

Flat View: This topic has 3 replies on 1 page
Topic: split a string Previous Topic   Next Topic Topic: ACL for removable drives

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use