Solved

Sending WinPopup messages

Posted on 2002-04-08
1
455 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

705 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