3

I use Unmanaged Exports to create a native .dll from .NET .dll so I can access .NET code from Delphi without COM registration.

For example I have this .NET assembly:

using System;
using System.Collections.Generic;
using System.Text;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;

namespace DelphiNET
{
   [ComVisible(true)]
   [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
   [Guid("ACEEED92-1A35-43fd-8FD8-9BA0F2D7AC31")]
   public interface IDotNetAdder
   {
      int Add3(int left);
   }

   [ComVisible(true)]
   [ClassInterface(ClassInterfaceType.None)]
   public class DotNetAdder : DelphiNET.IDotNetAdder
   {
      public int Add3(int left)
      {
         return left + 3;
      }
   }

   internal static class UnmanagedExports
   {
      [DllExport("createdotnetadder", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
      static void CreateDotNetAdderInstance([MarshalAs(UnmanagedType.Interface)]out IDotNetAdder instance)
      {
         instance = new DotNetAdder();
      }
   }
}

When I define the same interface in Delphi, I can easily use the .NET object:

type
  IDotNetAdder = interface
  ['{ACEEED92-1A35-43fd-8FD8-9BA0F2D7AC31}']
    function Add3(left : Integer) : Integer; safecall;
  end;

procedure CreateDotNetAdder(out instance :  IDotNetAdder); stdcall;
  external 'DelphiNET' name 'createdotnetadder';

var
  adder : IDotNetAdder;
begin
  try
   CreateDotNetAdder(adder);
   Writeln('4 + 3 = ', adder.Add3(4));
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

See my Delphi question and answers for details.

My question:
Is something like this possible in FoxPro? I've tried the following which fails with Data type mismatch error on line createdotnetadder(@ldnw):

DECLARE createdotnetadder IN DelphiNET.dll object @ ldnw
ldnw = 0
createdotnetadder(@ldnw)
loObject = SYS(3096, ldnw)
? loObject.Add3(4)

Can I define interface in FoxPro similarly how I did it in Delphi? If not, can I use this .dll from FoxPro at all? I use Visual FoxPro 9.0 SP2. Thanks.

4

2 に答える 2

1

最も簡単な方法は、COM 登録を使用することです。もう 1 つの方法は、CLR を手動でホストすることです。Rick Strahl は、FoxPro からこれを行う方法について広範な投稿を行っています。

http://www.west-wind.com/wconnect/weblog/ShowEntry.blog?id=631

于 2010-03-02T23:05:57.580 に答える