Hi,


I have made a DLL coded in C#, and and executable in C#. I've already have the DLL referenced in my Exe project, so i cannot reference the DLL back to the Exe because it won't let me. Now what I need to do is, call a function within the Exe project from the DLL. Really what I want to do is, empty out a Rich Text Box field, in my form inside the Exe project, from the DLL file.

Any help?

I was thinking of making a pointer in the DLL file, and a timer in my Exe Project, and when the pointer's value returns 1 then it empties the RTB, and sets the pointer to 0.

But I don't know how to do that.... I know how to create the pointer, but don't know how to retrieve it in the Exe.

Please help!! ~ THANKS!!

Recommended Answers

All 2 Replies

Use an interface or a delegate. Here is an interface example:

.EXE Application

using System;
using System.Windows.Forms;
using daniweb.callbackDLL;

namespace daniweb
{
  public partial class FormCallback : Form, IClearTextBox
  {
    public FormCallback()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
      CallbackDLL.DoWork(); //this will clear the textbox
    }

    private void FormCallback_Load(object sender, EventArgs e)
    {
      CallbackDLL.RegisterCallback(this);
    }

    #region IClearTextBox Members
    void IClearTextBox.ClearTextBox()
    {
      textBox1.Text = string.Empty;
    }
    #endregion
  }
}

DLL Application

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace daniweb.callbackDLL
{
  public interface IClearTextBox
  {
    void ClearTextBox();
  }

  public static class CallbackDLL
  {
    private static IClearTextBox _callback;
    public static void RegisterCallback(IClearTextBox Callback)
    {
      _callback = Callback;
    }
    public static void DoWork()
    {
      //do whatever
      _callback.ClearTextBox();
      //do whatever else
    }
  }
}
commented: OMG.. Your the best! :D +1

OMG.. Your the best!!! :D THANK YOU!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.