Использование внешних dll: различия между версиями

Материал из Wiki МИАЦ ВО
Перейти к навигации Перейти к поиску
Строка 2: Строка 2:
 
Например,
 
Например,
 
***********************
 
***********************
<%Code%> using System;
+
<pre> using System;
 
using System.Collections.Generic;
 
using System.Collections.Generic;
 
using System.Linq;
 
using System.Linq;
Строка 71: Строка 71:
 
}
 
}
 
*************
 
*************
<%/Code%>
+
</pre>
 
В свойствах проекта выбираем вместо ANY x86
 
В свойствах проекта выбираем вместо ANY x86
 
В
 
В

Версия 18:32, 10 февраля 2015

Создаем в Visual Studio библиотеку классов C#. Если собираемся передавать в длл указатели, то открываем свойства проекта, вкладка Построение и добавляем галочку Разрешить небезопасный код. Например,

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.Xml;
using System.Xml;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace ManagedCSharpDLL
{
    public static class UnmanagedExports
    {
        [System.Reflection.Obfuscation(Feature = "DllExport")]
        public static void TestINT(int val1)
        {
            System.Windows.Forms.MessageBox.Show(val1.ToString());
        }

        [System.Reflection.Obfuscation(Feature = "DllExport")]
        public static string Canonicalize(string document)
        {
            XmlDsigExcC14NTransform xmlTransform = new XmlDsigExcC14NTransform();
            xmlTransform.LoadInput(document);
            System.Windows.Forms.MessageBox.Show(document.ToString());
            string result = new StreamReader((MemoryStream)xmlTransform.GetOutput()).ReadToEnd();
            //C# метод канокализации не добавляет в XPath неймсппейс
/*            result = s.Replace("<XPath>", "<XPath xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">");*/
            return result;
        }
        
        [System.Reflection.Obfuscation(Feature = "DllExport")]
        public static string Canonicalization(XmlNode node)
        {
            XmlDsigExcC14NTransform c14 = new XmlDsigExcC14NTransform();
            var nodeStream = new MemoryStream();
            XmlWriter writer = XmlWriter.Create(nodeStream);
            node.WriteTo(writer);
            writer.Flush();

            nodeStream.Position = 0;

            var transform = new XmlDsigExcC14NTransform();
            transform.LoadInput(node);
            var outputStream = (MemoryStream)transform.GetOutput(typeof(Stream));
            return new StreamReader(outputStream).ReadToEnd();

            //C# метод канокализации не добавляет в XPath неймсппейс
            // result = s.Replace("<XPath>", "<XPath xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">");
            //todo: Поверить после! Тут они не попадаются, проверить нечем. 
        }
      [System.Reflection.Obfuscation(Feature = "DllExport")]
        public static void TestCallback(string passedString)
        {
            string displayValue = passedString;
            string returnValue = String.Empty;

            MessageBox.Show("C#: About to call the Callback. displayValue=" + displayValue + ", returnValue=" + returnValue);
            MessageBox.Show("C#: Back from the Callback. displayValue=" + displayValue + ", returnValue=" + returnValue);
        }

    }
}
*************

В свойствах проекта выбираем вместо ANY x86 В