Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sending WinPopup messages

Posted on 2002-04-08
1
Medium Priority
?
474 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 600 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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

604 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