Solved

Sending WinPopup messages

Posted on 2002-04-08
1
405 Views
Last Modified: 2009-07-29
I wont to send winpopup messages from my Java application. I'm working on Win98 so i can't use net send as I could using WindowsNT!
0
Comment
Question by:ljuso
1 Comment
 
LVL 3

Accepted Solution

by:
msterjev earned 150 total points
ID: 6927461
JNI solution:

The Java class:

public class WinPopup
{
     static
     {
          System.loadLibrary("WinPopup");
     }
     
     protected String from;
     
     public WinPopup(String from)
     {
          this.from=from;
     }
     
     public boolean sendMessage(String computer,String to,String message)
     {
          return sendMessage(computer,from,to,message);
     }
     public native boolean sendMessage(String computer,String from,String to,String message);
}

Generate the header file:

javah WinPopup

Generate new dll project and add WinPopup.h into the project.
Add new C++ file and paste this:

#include <windows.h>
#include "WinPopup.h"

JNIEXPORT jboolean JNICALL Java_WinPopup_sendMessage(JNIEnv * env, jobject obj, jstring c, jstring f,jstring t, jstring m)
{
     
     BOOL success=false;
     DWORD msgLength;
     DWORD bytesWritten;

     const char * computer=env->GetStringUTFChars(c,0);
     const char * from=env->GetStringUTFChars(f,0);
     const char * to=env->GetStringUTFChars(t,0);
     const char * message=env->GetStringUTFChars(m,0);
     
     //Prepearing WinPopup message

     msgLength=lstrlen(from)+lstrlen(to)+lstrlen(message)+4;
     char * winPopMsg=new char[msgLength];
     lstrcpy(winPopMsg,from);
     lstrcpy(winPopMsg+lstrlen(from)+1,to);
     lstrcpy(winPopMsg+lstrlen(from)+1+lstrlen(to)+1,message);

     //Prepearing Mailslot

     
     char mailslot[256];
     lstrcpy(mailslot,"\\\\");
     lstrcat(mailslot,computer);
     lstrcat(mailslot,"\\mailslot\\messngr");

     //Opening Mailslot
     
     HANDLE fileHandle=CreateFile(mailslot,GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
     if(fileHandle!=NULL)
          success=WriteFile(fileHandle,winPopMsg,msgLength,&bytesWritten,NULL);

     //Cleaning

     delete winPopMsg;
     env->ReleaseStringUTFChars(c,computer);
     env->ReleaseStringUTFChars(f,from);
     env->ReleaseStringUTFChars(t,to);
     env->ReleaseStringUTFChars(m,message);

     if(success)
          return JNI_TRUE;
     else
          return JNI_FALSE;
}

Put the generate dll into the same directory as WinPopup class.
Test it with:

import java.io.*;

public class Test
{
     public static void main(String[] args)throws Exception
     {
          WinPopup wp=new WinPopup("Myself");
          String comp="Comp1";
          String to="Someone";
          String line;
          DataInputStream in=new DataInputStream(System.in);
          while(!(line=in.readLine()).equals(""))
          {
               wp.sendMessage(comp,to,line);
          }
     }
}


0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java virtual machine monitoring tools 3 39
mergeTwo  challenge 13 72
@SBGen Method 3 25
Java JRE greater than 1.6 5 24
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now