[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Delphi Communication with C# Dll

Posted on 2012-04-03
3
Medium Priority
?
1,954 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Accepted Solution

by:
rinfo earned 600 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

I originally wrote this article to compare SARDU and YUMI, but have now added Easy2Boot, since that is the one I currently use and find the easiest to create and alter.
Here in this article, you will get a step by step guidance on how to restore an Exchange database to a recovery database. Get a brief on Recovery Database and how it can be used to restore Exchange database in this section!
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

649 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