Solved

Sending WinPopup messages

Posted on 2002-04-08
1
446 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 241
import as existing maven project 3 41
learn programming 8 72
activeMQ Queue Messages Enqueued and Messages Dequeued 1 39
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

726 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