Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
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:

C#
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);
        //this activates the StartListen method that is listening for a UDP message.
        //the event is created in it
        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.
Posted
Comments
Sergey Alexandrovich Kryukov 3-Jan-14 13:53pm    
Why messing with ActiveX if you do .NET development?
—SA
Pavle Pecov 8-Jan-14 6:33am    
Because it's said from above. A guy who is project leader knows that Avaya systems has done something similar with ActiveX, and 'orders' me to do the same. No clear specification nor any documents provided.
Sergey Alexandrovich Kryukov 8-Jan-14 10:23am    
Well, not really a justification...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900