Hello all. Maybe the name of the topic is little bit confusing. Well, I have this huge issue and I can't get the end of it.
I have created an ActiveX dll component. It is used in Console Application which creates an instance of it and runs in tray. Here is the code:
class Program
{
public static string MSG;
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
static NotifyIcon tray = new NotifyIcon();
static void Main(string[] args)
{
Console.Title = "ActiveXConsole";
Program program = new Program();
IntPtr hWnd = FindWindow(null, "ActiveXConsole");
if (hWnd != IntPtr.Zero)
{
ShowWindow(hWnd, 0);
}
tray.Icon = new Icon("App.ico");
tray.Visible = true;
tray.Text = "ActiveXConsole";
tray.ShowBalloonTip(3000, "ActiveXConsole", "ActiveXConsole working...", ToolTipIcon.None);
program.ActivateActiveX();
}
public void ActivateActiveX()
{
ActiveXdll.Class1 activex = new ActiveXdll.Class1();
activex.OnMessage += new EventHandler<NewMessageArgs>(ProcessMessage);
activex.StartListen();
}
public void ProcessMessage(object sender, NewMessageArgs args)
{
IntPtr hWnd = FindWindow(null, "ActiveXConsole");
MSG = args.Message;
tray.ShowBalloonTip(3000, "ActiveXConsole", "UDP Message has arrived", ToolTipIcon.None);
}
}
}
The DLL actually receives UDP string on some port and 'translates' it into event, which is handled in the console application, as seen in the code above.
This works well so far, but I got stacked. Now I need to make web application that listens to these events. The reason I can't use the DLL directly in the web application, is that if the tab that activates it is opened more than once (thus will activate it more than once), the UDP socket listener will create some conflict because no more than one socket can be opened on the same port in the same time.
I know there is a way to do this since I've seen it in other software, but how? What is the best way to do it? Basically the console application creates instance of the ActiveX DLL and the events that are raised there are listened by a web application which does something when triggered.
Thanks in advance.