Note that there are some explanatory texts on larger screens.

plurals
  1. POInterface result delphi to c# - class define dll use in c#
    primarykey
    data
    text
    <p>I have a class define in dll. I export this class by interface. I use this dll and class in other Delphi project very good but I want use this class in c# but send error for me.</p> <p>Source DLL:</p> <pre><code>type IMyDate = interface ['{D032F796-167D-4B0D-851D-2AEEA226646A}'] Procedure Analyze_Date(var y:Integer; m,d:Integer); stdcall; end; TMyDate = Class(TInterfacedObject, IMyDate) Public Procedure Analyze_Date(var y:integer; m,d:Integer); stdcall; End; procedure TMyDate.Analyze_Date(var y:Integer; m, d: Integer); begin y:= m+d; end; Function MyDate:IMyDate; stdcall; begin result:= TMyDate.Create; end; exports MyDate; </code></pre> <p>Unit use in Delphi example:</p> <pre><code>Function MyDate:IMyDate; stdcall; external 'Project11'; implementation procedure TForm3.Button1Click(Sender: TObject); var md:IMyDate; var y,m,d:Integer; begin md:= MyDate; y:=10; m:=20; d:=30; md.Analyze_Date(y,m,d); showMessage(intTostr(y)); end; </code></pre> <p>Use in c# but get error:</p> <pre><code>//[Guid("D032F796-167D-4B0D-851D-2AEEA226646A")] public interface IMyDate { void Analyze_Date(ref int y, int m, int d); } [DllImport( "Project11.dll" , EntryPoint = "MyDate" , SetLastError = true , CallingConvention = CallingConvention.StdCall , CharSet = CharSet.Unicode)] public static extern IMyDate MyDate(); private void button9_Click(object sender, EventArgs e) { int y, m, d; IMyDate da; da = MyDate(); // get error this line y = 10; m = 20; d = 30; da.Analyze_Date(ref y, m, d); } </code></pre> <p><strong>Update</strong></p> <p>thank you for answer</p> <p>i add new function to Interface and class but my function only return false</p> <p>also my function and procedure in delphi is stdcall and interface in C# is normaly !!!</p> <pre><code>IMyDate = interface ['{D032F796-167D-4B0D-851D-2AEEA226646A}'] Function testing():Boolean; stdcall; end; TMyDate = Class(TInterfacedObject, IMyDate) Public Function testing():Boolean; stdcall; End; function TMyDate.testing(): Boolean; begin result:= true; end; </code></pre> <p>c#:</p> <pre><code>[ComImport, Guid("D032F796-167D-4B0D-851D-2AEEA226646A"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IMyDate { bool testing(); } [DllImport( "Project11.dll" , EntryPoint = "CreateMyDate"//"MyDate" , SetLastError = true , CallingConvention = CallingConvention.StdCall , CharSet = CharSet.Unicode)] public static extern void CreateMyDate(out IMyDate Date); Boolean b; b = da.testing(); //this line only return false if (b) { MessageBox.Show("ffff"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload