<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FWindows%2FDLL</id>
		<title>Csharp/CSharp Tutorial/Windows/DLL - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FWindows%2FDLL"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Windows/DLL&amp;action=history"/>
		<updated>2026-04-29T16:34:09Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Windows/DLL&amp;diff=6690&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Windows/DLL&amp;diff=6690&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Windows/DLL&amp;diff=6691&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Windows/DLL&amp;diff=6691&amp;oldid=prev"/>
				<updated>2010-05-26T12:20:15Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Call DLL API to move file==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
&lt;br /&gt;
    class Tester&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, EntryPoint = &amp;quot;MoveFile&amp;quot;,ExactSpelling = false, CharSet = CharSet.Unicode,SetLastError = true)]&lt;br /&gt;
        static extern bool MoveFile(string sourceFile, string destinationFile);&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            ExploreDirectory(new DirectoryInfo(&amp;quot;c:\\&amp;quot;));&lt;br /&gt;
        }&lt;br /&gt;
        private static void ExploreDirectory(DirectoryInfo dir)&lt;br /&gt;
        {&lt;br /&gt;
            string newDirectory = &amp;quot;newTest&amp;quot;;&lt;br /&gt;
            DirectoryInfo newSubDir =dir.CreateSubdirectory(newDirectory);&lt;br /&gt;
            FileInfo[] filesInDir = dir.GetFiles();&lt;br /&gt;
            foreach (FileInfo file in filesInDir)&lt;br /&gt;
            {&lt;br /&gt;
                string fullName = newSubDir.FullName + &amp;quot;\\&amp;quot; + file.Name;&lt;br /&gt;
                file.CopyTo(fullName);&lt;br /&gt;
                Console.WriteLine(file.FullName);&lt;br /&gt;
            }&lt;br /&gt;
            filesInDir = newSubDir.GetFiles();&lt;br /&gt;
            int counter = 0;&lt;br /&gt;
            foreach (FileInfo file in filesInDir)&lt;br /&gt;
            {&lt;br /&gt;
                string fullName = file.FullName;&lt;br /&gt;
                if (counter++ % 2 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    Tester.MoveFile(fullName, fullName + &amp;quot;.bak&amp;quot;);&lt;br /&gt;
                    Console.WriteLine(&amp;quot;{0} renamed to {1}&amp;quot;,fullName, file.FullName);&lt;br /&gt;
                }else{&lt;br /&gt;
                    file.Delete();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;{0} deleted.&amp;quot;,fullName);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            newSubDir.Delete(true);&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Compile to dll==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;// compile with: csc /r:..\logdriver.dll /target:library logaddintofile.cs&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.IO;&lt;br /&gt;
public class LogAddInToFile&lt;br /&gt;
{&lt;br /&gt;
    StreamWriter streamWriter;&lt;br /&gt;
    &lt;br /&gt;
    public LogAddInToFile()&lt;br /&gt;
    {&lt;br /&gt;
        streamWriter = File.CreateText(@&amp;quot;logger.log&amp;quot;);&lt;br /&gt;
        streamWriter.AutoFlush = true;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void Log(string message)&lt;br /&gt;
    {&lt;br /&gt;
        streamWriter.WriteLine(message);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Fiber==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class fmrFibers : System.Windows.Forms.Form {&lt;br /&gt;
    private System.Windows.Forms.ListBox lstFibers;&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    extern static IntPtr ConvertThreadToFiber(int fiberData);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    extern static IntPtr CreateFiber(int size, System.Delegate function, int handle);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    extern static IntPtr SwitchToFiber(IntPtr fiberAddress);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    extern static void DeleteFiber(IntPtr fiberAddress);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    extern static int GetLastError();&lt;br /&gt;
    delegate void SetTextOutputToEventLog(int number);&lt;br /&gt;
    public fmrFibers() {&lt;br /&gt;
        this.lstFibers = new System.Windows.Forms.ListBox();&lt;br /&gt;
        this.SuspendLayout();&lt;br /&gt;
        this.lstFibers.Size = new System.Drawing.Size(320, 212);&lt;br /&gt;
        this.ResumeLayout(false);&lt;br /&gt;
        Thread t1 = new Thread(new ThreadStart(NewThreadToFiberExecution));&lt;br /&gt;
        t1.Start();&lt;br /&gt;
    }&lt;br /&gt;
    void OutputLog(int fiberNumber) {&lt;br /&gt;
        this.Invoke(new AddToListBox(SetText), new object[] { fiberNumber });&lt;br /&gt;
        SwitchToFiber(obj);&lt;br /&gt;
    }&lt;br /&gt;
    void SetText(int message) {&lt;br /&gt;
        lstFibers.Items.Add(&amp;quot;Fiber &amp;quot; + message.ToString() + &amp;quot; added this&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    delegate void AddToListBox(int message);&lt;br /&gt;
    System.IntPtr obj;&lt;br /&gt;
    void NewThreadToFiberExecution() {&lt;br /&gt;
        try {&lt;br /&gt;
            SetTextOutputToEventLog stof = new SetTextOutputToEventLog(OutputLog);&lt;br /&gt;
            obj = ConvertThreadToFiber(0);&lt;br /&gt;
            long l1 = GetLastError();&lt;br /&gt;
            System.IntPtr retVal1 = CreateFiber(500, stof, 1);&lt;br /&gt;
            if (GetLastError() != 0) throw new Exception(&amp;quot;Create Fiber failed!!&amp;quot;);&lt;br /&gt;
            IntPtr fiber1return = SwitchToFiber(retVal1);&lt;br /&gt;
            if (GetLastError() != 0) throw new Exception(&amp;quot;Create Fiber failed!!&amp;quot;);&lt;br /&gt;
            DeleteFiber(retVal1);&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            throw e;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [STAThread]&lt;br /&gt;
    static void Main() {&lt;br /&gt;
        Application.Run(new fmrFibers());&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Invoke MessageBox in Dll==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;user32.dll&amp;quot;)]&lt;br /&gt;
        public static extern int MessageBox(IntPtr hwnd, String text, String caption, uint type);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            MessageBox(new IntPtr(0), &amp;quot;Greetings from Platform Invoke&amp;quot;, &amp;quot;Platform Invoke&amp;quot;, 0);&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Marshal a function from Dll to a delegate==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr LoadLibrary(string dllName);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        delegate int MessageBoxDelegate(IntPtr hwnd,&lt;br /&gt;
            [MarshalAs(UnmanagedType.LPWStr)]string text,&lt;br /&gt;
            [MarshalAs(UnmanagedType.LPWStr)]string caption,&lt;br /&gt;
            int type);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr userApi = LoadLibrary(&amp;quot;user32.dll&amp;quot;);&lt;br /&gt;
            IntPtr msgBoxAddress = GetProcAddress(userApi, &amp;quot;MessageBoxW&amp;quot;); // unicode (wide) message box&lt;br /&gt;
            MessageBoxDelegate mbd = (MessageBoxDelegate)Marshal.GetDelegateForFunctionPointer(msgBoxAddress,typeof(MessageBoxDelegate));&lt;br /&gt;
            mbd(IntPtr.Zero, &amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, 0);&lt;br /&gt;
            DoSomething(mbd);&lt;br /&gt;
        }&lt;br /&gt;
        static void DoSomething(MessageBoxDelegate mbd)&lt;br /&gt;
        {&lt;br /&gt;
            mbd(IntPtr.Zero, &amp;quot;Work completed.&amp;quot;, &amp;quot;Work Progress&amp;quot;, 0);&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using load library from Dll==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr LoadLibrary(string dllName);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        delegate int MessageBoxDelegate(IntPtr hwnd,&lt;br /&gt;
            [MarshalAs(UnmanagedType.LPWStr)]string text,&lt;br /&gt;
            [MarshalAs(UnmanagedType.LPWStr)]string caption,&lt;br /&gt;
            int type);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr userApi = LoadLibrary(&amp;quot;user32.dll&amp;quot;);&lt;br /&gt;
            IntPtr msgBoxAddress = GetProcAddress(userApi, &amp;quot;MessageBoxW&amp;quot;); // unicode (wide) message box&lt;br /&gt;
            MessageBoxDelegate mbd = (MessageBoxDelegate)Marshal.GetDelegateForFunctionPointer(msgBoxAddress,typeof(MessageBoxDelegate));&lt;br /&gt;
            mbd(IntPtr.Zero, &amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, 0);&lt;br /&gt;
            DoSomething(mbd);&lt;br /&gt;
        }&lt;br /&gt;
        static void DoSomething(MessageBoxDelegate mbd)&lt;br /&gt;
        {&lt;br /&gt;
            mbd(IntPtr.Zero, &amp;quot;Work completed.&amp;quot;, &amp;quot;Work Progress&amp;quot;, 0);&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>