Solved

Delphi Communication with C# Dll

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
Progress
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…

724 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