imort delphi dll

  • Thread starter Thread starter erdosa
  • Start date Start date
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)
 
erdosa,

What is the PChar type? I am not familiar with delphi, so can you
indicate what it represents?
 
(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/
 
(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);
 
Back
Top