• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1990
  • Last Modified:

Delphi Communication with C# Dll

Hi,
I am a Delphi Developer and very new to C#.
I am currently looking out for help on the following topic.
I have an existing application in Delphi 7 and a newly created C# Dll.
The requirement is that the Delphi would be sending a SQL String to the C# Dll, which inturn sends the formatted String to the Delpi Application.
  Please suggest me, how to establish connection betweeen Delphi and C#.

Thanks in advance,
Karthick.
0
arrowpointplc
Asked:
arrowpointplc
1 Solution
 
rinfoCommented:
C# are what is called as managed code and according to dotnet Delphi codes are unmanaged code.
It takes some work around for interaction between managed and unmanaged code.
Firstly about the dll if you have created the dll it would be better to make some modification in the code.
1. dll has to be used as com object.
2. create some interfaces to hold the functions.
    Your dll class should implement these interfaces

   // IAddInterface.cs
  public interface IAddInterface
  {
     returntype functionname(partmeters passed)      
  }
  //yourdll.cs
  [ClassInterface(ClassInterfaceType.None)]
  public class yourDLL : IAddInterface
  {
      public returntype  functionname(parameters)
        {
             return result of functionname
        }
  }

  compile the codes for the dll in console mode.

  csc /t:library /out:yourdll  *.cs

  register the assembly as a com object and create a typelibrary for delphi as well
  regasm yourdll.dll /tlb:Add.tlb
 
  this will create a delphi typelib  yourdll_tlb  as well

  Add this tlb in your delphi code file uses declaration.
  Besides you also need to add comobj in the uses.
  tlb file has to be copied to bin directory or the directory where the exe will be created in
  the delphi project directory.
  Now you can call the functions in the dll file this way
 
  procedure TForm1.Button1Click(Sender: TObject);
  var
  intfRef: IAddInterface;
  result:resulttype;
  begin
  intfRef := CreateComObject(CLASS_yourdllclassname_) as IAddInterface;
  result := intfRef.functionname(parameters);
  end;
0
 
DhaestCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now