Open Source Messenger for Any Version of Windows

Environment: VC6, WIN XP SP1

While I was writing a LAN (Local Area Network) chat program, I noticed that many people on my LAN use different programs for message sending and that not all of them are compatible with other programs. The second problem I noticed was that many of them don't work on Win95/98. So, I decided to add this functionality to my program. I started to search for a universal method for all Windows versions and most message-sending programs and I discovered that the best solution is to add a MAILSLOT mechanism to my program (along with some others). The first place I searched was MSDN and CodeGuru, but I didn't find any complete solution. That's the main reason I wrote this article.

I wrote a function that writes to the mailslot (I saw how to do that on CodeGuru) and a simple class that reads from the mailslot (I found many explanations and put all of them together—mostly from "PJ Naughter"). I also wrote a simple project so you can see how to link these two things and put everything in the right places.

Here are the steps you need to do:

  1. Add "mailslot.h" and "mailslot.cpp" to your project.
  2. Create a CMailSlot instance in your main class (for example, m_serverMailSlot).
  3. Add an OnTimer event to your project and somewhere set the Timer. For example, you can do that in OnInitDialog():
    SetTimer(timerID, 2000, NULL);    //this is for 2 seconds
  4. Create a CheckForNewMessage() function. That is the place where you will be calling an m_serverMailSlot.Read() function.
  5. In the OnTimer() function, call the CheckForNewMessage() function, which will check for new messages and display them (if there are any waiting).

That is all. I know that there are better ways to send messages, but this is the most-used method so you will be able to receive messages from many different programs and to use it on any Windows operating system.

If you have any questions or need some extra help with this, e-mail me... If there are any suggestions or comments, you are most welcome to contact me, too.

You can download "mailslot.h", "mailslot.cpp" (contains CServerMailslot), and "sendfun.txt". You can also download the sample project and executable file.

Downloads

Download executable - 72 Kb
Download demo project - 32 Kb
Download source - 3 Kb


Comments

  • Nice! But one question...

    Posted by Legacy on 03/05/2003 12:00am

    Originally posted by: VaKa

    Your App nice and very helpfull for me in understanding mailslot messaging.
    
    

    But I noticed that if I send a message from one PC to another, second PC receives that message multiple times.
    (in described case one PC running Windows NT4, another - Windows 98)

    Can You help me in understanding that?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Wednesday, September 24, 2014 8:00 AM - 9:00 AM PDT According to a recent Forrester Research report, many companies are choosing low-code platforms over traditional programming platforms, due to the speed with which low-code apps can be assembled and tested. With customer-facing applications on the rise, traditional programming platforms simply can't keep up with the "short schedules and rapid change cycles" required to develop these applications. Check out this upcoming webinar and join Clay Richardson from …

  • Live Event Date: September 17, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this upcoming eSeminar and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds