Solved

Delphi Communication with C# Dll

Posted on 2012-04-03
3
1,703 Views
Last Modified: 2012-08-02
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
Comment
Question by:arrowpointplc
3 Comments
 
LVL 9

Accepted Solution

by:
rinfo earned 150 total points
ID: 37805415
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 38249578
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 80
Win 7 OS unable to install Win updates 3 141
Ransomware attacks 5 87
Path to Python 9 110
A list of useful business intelligence software.
Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now