imort delphi dll

E

erdosa

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: ^’rectangle’. (not "Hello")

what is tha problem???

Thanks Erdosa

(e-mail address removed)
 
N

Nicholas Paldino [.NET/C# MVP]

erdosa,

What is the PChar type? I am not familiar with delphi, so can you
indicate what it represents?
 
C

Chad Z. Hower aka Kudzu

(e-mail address removed)-spam.invalid (erdosa) wrote in [email protected]:
I want use dll (Delphi 7) in c#

Delphi 7 is a native compiler. Do you want to use a DLL made by Delphi 7?
procedure GetNev(s:pChar);export;

Yes, it appears so...
Message is: ^’rectangle’. (not "Hello")

Your PChar is porbably not mapped in the P/Invoke correctly. Check to see how
other P/Invokes are handled with PChar. You have to marshal it IIRC since its
not a native type.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
 
C

Chris R. Timmons

(e-mail address removed)-spam.invalid (erdosa) wrote in
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: ^’rectangle’. (not "Hello")

what is tha problem???

Erdosa,

You should specify the stdcall calling convention on your Delphi
method. (The export directive does not need to be specified on the
method, because the "exports GetNev" does the actual exporting):

procedure GetNev(s:pChar); stdcall;

The PChar type is not UniCode. PWideChar is. Make sure the
DllImport's CharSet property matches the kind of character pointer
the Delphi method expects.

If GetNev is declared with a PChar parameter, use this DllImport
attribute:

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

If GetNev is declared with a PWideChar parameter, use this DllImport
attribute:

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top