Addhandler Funktion bei dynamisch eingebundener DLL

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Steven.

    Ich bin mir nicht sicher ob du das meinst, bei einer Open API hatte ich mal etwas geschrieben um diese einzubinden.

    Das sieht dann so aus:

    VB.NET-Quellcode

    1. Public ChatlogHandler As ChatLibrary.Chat = ChatLibrary.Chat.GetInstance()
    2. AddHandler ChatlogHandler.OnChatMessage, AddressOf OnChatMessage
    3. Public Sub OnChatMessage(time As DateTime, message As String)
    4. 'DLL Übermittelt ihr den wert
    5. End Sub


    Und das ist die DLL dazu, vielleicht hilft es dir:

    Die DLL wurde mit hilfe des Codes von der Open shadowAPI2 erstellt und
    stammt nicht von mir deshalb wird dieser Code nicht weiter von mir Supportet.

    VB.NET-Quellcode

    1. [/font]using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5. using System.Threading.Tasks;
    6. using System.Drawing;
    7. using System.IO;
    8. using System.Security.AccessControl;
    9. namespace ChatLibrary
    10. {
    11. public class Chat
    12. {
    13. private static Chat instance;
    14. private FileSystemWatcher watcher;
    15. private StreamReader reader;
    16. private FileInfo info;
    17. private const string CHATLOG_FILE = "......txt";
    18. private string chatlogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), ".....");
    19. public delegate void OnChatMessageReceived(DateTime time, String message);
    20. public event OnChatMessageReceived OnChatMessage;
    21. private Chat()
    22. {
    23. try
    24. {
    25. reader = new StreamReader(new FileStream(Path.Combine(chatlogPath, CHATLOG_FILE), FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.Default, true);
    26. reader.ReadToEnd();
    27. info = new FileInfo(Path.Combine(chatlogPath, CHATLOG_FILE));
    28. watcher = new FileSystemWatcher();
    29. watcher.Path = chatlogPath;
    30. watcher.Filter = CHATLOG_FILE;
    31. watcher.Changed += ChangeReceived;
    32. watcher.EnableRaisingEvents = true;
    33. }
    34. catch (Exception)
    35. {
    36. chatlogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), ".........");
    37. reader = new StreamReader(new FileStream(Path.Combine(chatlogPath, CHATLOG_FILE), FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.Default, true);
    38. reader.ReadToEnd();
    39. info = new FileInfo(Path.Combine(chatlogPath, CHATLOG_FILE));
    40. watcher = new FileSystemWatcher();
    41. watcher.Path = chatlogPath;
    42. watcher.Filter = CHATLOG_FILE;
    43. watcher.Changed += ChangeReceived;
    44. watcher.EnableRaisingEvents = true;
    45. }
    46. }
    47. internal void ChangeReceived(object ob, FileSystemEventArgs e)
    48. {
    49. info.Refresh();
    50. if (info.Length < reader.BaseStream.Position)
    51. {
    52. reader.BaseStream.Position = 0;
    53. reader.DiscardBufferedData();
    54. }
    55. String line = "";
    56. while (!reader.EndOfStream)
    57. {
    58. line = reader.ReadLine();
    59. if (line == "")
    60. continue;
    61. else
    62. {
    63. List<String> splitted = line.Split(' ').ToList();
    64. DateTime date = DateTime.Parse(splitted[0].Remove(0, 1).Remove(splitted[0].Length - 2));
    65. splitted.RemoveAt(0);
    66. if (OnChatMessage != null)
    67. OnChatMessage(date, string.Join(" ", splitted));
    68. }
    69. }
    70. }
    71. public static Chat GetInstance()
    72. {
    73. if (instance == null)
    74. instance = new Chat();
    75. return instance;
    76. }
    77. }
    78. }


    LG Steven