Solved

Delphi Communication with C# Dll

Posted on 2012-04-03
3
1,659 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If your app took Google’s lash recently, here are the 5 most likely reasons.
Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
This video will demonstrate how to find the puppet warp tool from the edit menu and where to put the points to edit.
Viewers will learn how to use the Hootsuite Dashboard.

760 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

23 Experts available now in Live!

Get 1:1 Help Now