c# - 为 MT4 导出非托管 C# DLL(带命名空间)

标签 c# dll namespaces unmanaged metatrader4

我在 中有一个代码C# ,此代码应导出为未加密的代码,因为它会被 使用。 MetaTrader 终端 4 作为 #import -ed 库 ( .dll )。

The big questions are:

Q1 ) Can I use system.net and system.net.mail namespaces for export as unmanaged DLL?

Q2 ) If not, what is a better solution for this ( export DLL as unmanaged and with a reference to namespaces ) ?

Q3 ) Why export does not work for this function (EnviarCorreo)?



谢谢。
using System;
using System.Text;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
using System.Net;
using System.Net.Mail;
namespace Testme
{
    class Test
    {
        [DllExport("EnviarCorreo", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.LPWStr)]
        public static int EnviarCorreo(string ServidorSMTP, string usuario, string pass, bool HTML, string Asunto, string Cuerpo, string Desde, string Para)
    {
        MailMessage mail = new MailMessage();
        //direccion desde
        mail.From = new MailAddress("tester@domain.com", "Name");
        mail.ReplyTo = new MailAddress("info@domain.com");
        MailAddress toa = new MailAddress("admin@domain.com");

        string contenido = "Aquí vamos a escribir en HTML <br>Para ver</br>";
        mail.BodyEncoding = Encoding.Unicode;
        mail.SubjectEncoding = Encoding.Unicode;
        mail.To.Clear();
        mail.To.Add(toa);
        mail.Subject = "PRUEBA DE CORREO";
        mail.Body = contenido;// +Constants.vbCr + Constants.vbLf;
        mail.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient("mail.domain.com");
        smtp.Credentials = new NetworkCredential("tester@domain.com", "blabla");
        smtp.Send(mail);
        return 158;
    }

        [DllExport("Add", CallingConvention = CallingConvention.StdCall)]
        public static int Add(int left, int right)
        {
            return left + right;
        }

        [DllExport("Sub", CallingConvention = CallingConvention.StdCall)]
        public static int Sub(int left, int right)
        {
            return left - right;
        }

        [DllExport("AddDouble", CallingConvention = CallingConvention.StdCall)]
        public static double AddDouble(double left, double right)
        {
            return left + right;
        }

        [DllExport("AddFloat", CallingConvention = CallingConvention.StdCall)]
        public static float AddFloat(float left, float right)
        {
            return left + right;
        }

    }
}

最佳答案

.Net 是一种托管语言,因此您不能只创建非托管 dll。由于您的 dll 取决于框架,因此稍微复杂一些。有很多方法可以做到,但它们需要一些工作。看看这篇文章的答案。

https://social.msdn.microsoft.com/Forums/en-US/afb244b3-1cd4-48b4-93ba-f019fdce6a8e/creating-an-unmanaged-dll-in-c?forum=csharplanguage

关于c# - 为 MT4 导出非托管 C# DLL(带命名空间),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37305561/

相关文章:

c# - 在 Delphi 7 中调用 .net 4.0 内置的 dll

module - Rebol模块中的单词是如何绑定(bind)的?

c# - 使用 EWS 阅读电子邮件时处理非法 XML 值

c# - Int[].Contains 在 EF6 中不起作用

c# - 命名管道 C# 服务器 C++ .dll 客户端不工作?

c# - 如何创建虚拟音频设备

Python 函数的 __dict__

java - Java 项目中嵌入 BaseX 的 "No namespace declared for bin:bin"错误

c# - 如何将二进制补码形式的字节转换为其整数值? C#

c# - 将观察者集合分配给列表框时出错