ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码

C#调用Delphi接口ITest = interface(2/2)

来源:网络整理     时间:2016-05-26     关键词:interface,Delphi

本篇文章主要介绍了"C#调用Delphi接口ITest = interface",主要涉及到interface,Delphi方面的内容,对于Delphijrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播感兴趣的同学可以参考一下: 首先创建一个delphi的DLL工程library testintfdll;{ Important note about DLL memory manageme...

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace CShapeTestClient
{
    [ComVisible(true)]
    [ComImport, Guid("000A0299-A27A-4D35-9721-419AE6E83869"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface ITest
    {
        [MethodImplAttribute(MethodImplOptions.PreserveSig)]
        void ShowMessage([MarshalAs(UnmanagedType.AnsiBStr)] string msg);
        [MethodImplAttribute(MethodImplOptions.PreserveSig)]
        int Add(int a, int b);
    }

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        [DllImport("testintfdll.dll", EntryPoint = "GetImpl",CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        private static extern void GetImpl([MarshalAs(UnmanagedType.Interface)] out ITest instance);

        private void button1_Click(object sender, EventArgs e)
        {
            ITest tester;
            GetImpl(out tester);
            tester.ShowMessage(textBox1.Text);
            this.Text = tester.Add(100, 50).ToString();
        }
    }
}

以上就介绍了C#调用Delphi接口ITest = interface,包括了interface,Delphi方面的内容,希望对Delphijrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_1324096_2.html

相关图片

相关文章