C # Method of calling Delphi's DLL

Source: Internet
Author: User

Several key technical points:

1, C # to the unmanaged way to call the DLL;
2, C # to tidy up the drawing data generated in advance defined the format of the XML file, passed to the DLL;
3, DLL parsing XML file, according to the corresponding format, requirements, drawing;
4, DLL output GIF file (after comparison GIF image distortion rate is small, and the smallest file size);
5, C # loading GIF files, to the front desk display.

Library Icdll;

Uses
Sysutils;

function Check22:pchar;stdcall;
Begin
Result:= ' OK ';
End

Exports
Check22;
Begin
End.


2. Make a call in C #.

Using System.Runtime.InteropServices;//must reference
namespace Testdll
{
    public Partial class Form1:form
    {
        [DllImport (" Icdll.dll ")]
        public static extern StringBuilder Check22 ();
 & nbsp;      public Form1 ()
        {
             InitializeComponent ();
       }
        private void Form1_Load (object sender, EventArgs e)
  & nbsp;     {

               StringBuilder result= Check22 (); Result here is the return value.


       }

   }

Instance after

May 22, 2007, Tuesday 05:46
----------------------Delphi-------------------

procedure Getsqldata (Asource:pchar; Adest:pchar; Adestsize:integer); stdcall;
Var
s:string;
Begin
If Asource = nil then Exit;
S: = Format ('%s passed by! ', [Asource]);
Move (S[1], adest^, Min (Adestsize, Length (S) +1));
End {Getsqldata}
Exports
Getsqldata;
----------------------C #-------------------
[DllImport (@ "TempLib.dll")]
public static extern void Getsqldata (string asource, StringBuilder adest, int adestsize);
private void Button1_Click (object sender, EventArgs e)
{
StringBuilder vdest = new StringBuilder (1024);
Getsqldata ("Zswang", vdest, 1024);
Text = Vdest.tostring ();
}

   Summary: To return the string, 1. In Delphi return is Pchar type, receive with StringBuilder in C #, there is no special notice, and other DLL basically same, Note that string can be replaced with Pchar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.