er**********@eduweb-dot-hu.no-spam.invalid (erdosa) wrote in
news:40**********@127.0.0.1:
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);
--
Hope this helps.
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/