Ping And Live Connect


Makefile

################################################################################
#### make file for plugins ####
#
#  
#  Setting in your environment or the command line will determine what you 
#   build.  
#
#   JRI_ROOT    the root directory for this sdk (i.e. [drive]:\nspi30)
#
#   JDK_ROOT    the root for the java compiler (javac). If not specified
#               defaults to JRI_ROOT
#
#   DEBUG       debug version   
#
#   i.e. 
#   nmake -f makefile DEBUG=1 JDK_ROOT=c:\jdk
#   
# Will create four directory:
#   objs        your objects and plugin
#   classes     your java classes
#   _gen        your headers from java classes
#   _stubs      your stubs from java classes
#   
################################################################################

# adding java classes and stubs generation rules
.SUFFIXES : .class .h .java

!if !defined(JRI_ROOT)
JRI_ROOT = c:\nspi30
!endif

JDK_ROOT = c:\java

!if "$(OS)" == "Windows_NT"
NULL=
!else
NULL=nul
!endif

TARGET  = npavi32

################################################################################
# Objects files
#
OBJS    = \
        .\objs\npshell.obj \
        .\objs\AviPlayer.obj \
        .\objs\netscape_plugin_Plugin.obj

CLASSES = \
        .\classes\AviPlayer.class 

GEN     = \
        .\_gen\AviPlayer.h \

STUBS   = \
        .\_stubs\AviPlayer.c \

RES     = \
        .\objs\$(TARGET).res

ZIP     = \
        .\_gen\java_lang_Object.h \
        .\_gen\netscape_plugin_Plugin.h \
        .\_stubs\netscape_plugin_Plugin.c

################################################################################
# Libraries
#
LIBS    = \
    WINMM.LIB \
    kernel32.lib \
    user32.lib \
    gdi32.lib \
    comdlg32.lib \
    wsock32.lib \
    $(JRI_ROOT)\lib\jrt3221.lib


################################################################################
# Options and flags
#
CPP_INC     = /I $(JRI_ROOT)\include /I_gen
CPP_OPTS    = /nologo /W3 /GX /Od /c
CPP_DEFS    = /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "_WINDLL" /D "_MBCS" /D "XP_PC"

JAVA_CLASSES  = -classpath $(JRI_ROOT)\classes\moz3_0.zip;.

LINK_FLAGS   = \
        /nologo\
        /entry:"DllEntryPoint"\
        /subsystem:windows\
        /dll\
        /incremental:no\
        /machine:I386\
        /def:$(TARGET).def\
        /out:.\objs\$(TARGET).dll\
        /implib:.\objs\$(TARGET).lib

!if "$(DEBUG)" == "1"

CPP_OPTS    = /MDd /Zi $(CPP_OPTS)
CPP_DEFS    = /D "_DEBUG" /D "STRICT" $(CPP_DEFS)

LINK_FLAGS   = $(LINK_FLAGS) /DEBUG

!else

CPP_OPTS    = /MD $(CPP_OPTS)
CPP_DEFS    = /D "NDEBUG" $(CPP_DEFS)

!endif


CPP_FLAGS   = $(CPP_OPTS) $(CPP_DEFS) $(CPP_INC)
RC_OPTS     = /l 0x409


################################################################################
# Tools
#
RSC     = rc.exe
CPP     = cl.exe
LINK    = link.exe
JAVAC   = $(JDK_ROOT)\bin\javac.exe 
JAVAH   = $(JRI_ROOT)\bin\javah.exe  			# must be the jri version


################################################################################
# Explicit Rules
#

all : java .\objs\$(TARGET).dll

dirs : 
    if not exist .\classes mkdir classes
    if not exist .\_gen mkdir _gen
    if not exist .\_stubs mkdir _stubs
    if not exist .\objs mkdir objs

java : dirs $(CLASSES) $(ZIP) generate $(GEN) $(STUBS)
    cd ..

generate : 
    cd classes

.\objs\$(TARGET).dll : $(TARGET).def $(OBJS) $(RES)
    $(LINK) @<<
        $(LIBS) $(LINK_FLAGS) $(OBJS) $(RES)
<<

# header and stubs files depending upon the zip file must be explicitly set
.\_gen\netscape_plugin_Plugin.h : $(JRI_ROOT)\classes\moz3_0.zip
    $(JAVAH) $(JAVA_CLASSES) -jri -d _gen netscape.plugin.Plugin

.\_stubs\netscape_plugin_Plugin.c : $(JRI_ROOT)\classes\moz3_0.zip
    $(JAVAH) $(JAVA_CLASSES) -jri -stubs -d _stubs netscape.plugin.Plugin

.\_gen\java_lang_Object.h : $(JRI_ROOT)\classes\moz3_0.zip 
    $(JAVAH) $(JAVA_CLASSES) -jri -d _gen java.lang.Object


clean :
        del ".\objs\$(TARGET).dll"
        del ".\objs\$(TARGET).exp"
        del ".\objs\$(TARGET).lib"
        del ".\objs\$(TARGET).res"
        del ".\objs\npshell.obj"
        del ".\objs\npwin.obj"
        del ".\objs\plgwnd.obj"
        del ".\objs\avijava.obj"
        del ".\objs\AviObserver.obj"
        del ".\objs\AviPlayer.obj"
        del ".\objs\cavi.obj"
        del ".\objs\netscape_plugin_Plugin.obj"

        del ".\classes\AviPlayer.class"
        del ".\classes\AviObserver.class"

        del ".\_gen\AviObserver.h"
        del ".\_gen\AviPlayer.h"
        del ".\_gen\java_lang_Object.h"
        del ".\_gen\netscape_plugin_Plugin.h"

        del ".\_stubs\AviObserver.c"
        del ".\_stubs\AviPlayer.c"
        del ".\_stubs\netscape_plugin_Plugin.c"


################################################################################
# Implicit Rules
#
.java{.\classes}.class:
    $(JAVAC) $(JAVA_CLASSES) -d classes $<

{.\classes}.class{.\_gen}.h:
    $(JAVAH) $(JAVA_CLASSES) -jri -d ..\_gen $(*B)

{.\classes}.class{.\_stubs}.c:
    $(JAVAH) $(JAVA_CLASSES) -jri -stubs -d ..\_stubs $(*B)

{.\_stubs}.c{.\objs}.obj:
    $(CPP) $(CPP_FLAGS) $< /Fo$*

.c{.\objs}.obj:
    $(CPP) $(CPP_FLAGS) $< /Fo$*

.cpp{.\objs}.obj:
    $(CPP) $(CPP_FLAGS) $< /Fo$*

.rc{.\objs}.res:
    $(RC) $(RC_FLAGS) /fo $*.res $< 



npshell.cpp

#define IMPLEMENT_AviPlayer
#include <windows.h>
#include <string.h>
#include "npapi.h"
#include "npupp.h"
#include "AviPlayer.h"
#include <stdio.h>
NPP i;FARPROC D;HWND W;char aa[200];char bb[100];
jref NPP_GetJavaClass(void)
{
	JRIEnv* env = NPN_GetJavaEnv();
	return init_AviPlayer(env);
}
LRESULT CALLBACK P(HWND w, UINT x, WPARAM y, LPARAM z)
{
	if ( x == WM_LBUTTONDOWN)
        MessageBox(0,"hi","bye",0);
        if ( x == WM_USER+1)
        {
        HDC h = GetDC(w);
        TextOut(h,1,1,aa,strlen(aa));
        ReleaseDC(w,h);
        }
        return CallWindowProc(D, w,x,y,z);
}
NPError NP_LOADDS NPP_SetWindow(NPP instance, NPWindow* w)
{    
if (!w)    return NPERR_GENERIC_ERROR;
if (!instance)     return  NPERR_INVALID_INSTANCE_ERROR;
if (!w->window) return NPERR_NO_ERROR;
i = instance;
D=(FARPROC)::SetWindowLong(w->window,GWL_WNDPROC,(LONG)P);
W=w->window;
return NPERR_NO_ERROR;
}
struct o {
unsigned char Ttl,Tos,Flags,OptionsSize,*OptionsData;
};
struct {
DWORD Address;
unsigned long  Status,RoundTripTime;
unsigned short DataSize,Reserved;
void *Data;                  
struct o  Options;
} E;
HANDLE hIP;WSADATA wsa;HANDLE hIcmp;DWORD *dwIPAddr;struct hostent *phostent;
DWORD d;struct o I;
HANDLE ( WINAPI *pIcmpCreateFile )( VOID );
BOOL ( WINAPI *pIcmpCloseHandle )( HANDLE );
DWORD (WINAPI *pIcmpSendEcho)(HANDLE,DWORD,LPVOID,WORD,LPVOID,LPVOID,DWORD,DWORD);
typedef HANDLE (WINAPI *FARPROC1)(void);
typedef BOOL (WINAPI *FARPROC2)(HANDLE );
typedef DWORD (WINAPI *FARPROC3)(HANDLE,DWORD,LPVOID,WORD,LPVOID,LPVOID,DWORD,DWORD);
extern "C" JRI_PUBLIC_API(void) native_AviPlayer_setTimeOut(JRIEnv* env, struct AviPlayer* self, JRIMethodThunk* method,			     jint timeout){}
extern "C" JRI_PUBLIC_API(jbool) native_AviPlayer_play(JRIEnv* env, struct AviPlayer* self, JRIMethodThunk* method,		       jbool isAsync){		return TRUE;}
extern "C" JRI_PUBLIC_API(jbool) native_AviPlayer_stop(JRIEnv* env, struct AviPlayer* self, JRIMethodThunk* method,jint isAsync)
{
hIcmp = LoadLibrary( "ICMP.DLL" );
WSAStartup( 0x0101, &wsa );  
phostent = gethostbyname( "www.microsoft.com");
dwIPAddr = (DWORD *)( *phostent->h_addr_list );
pIcmpCreateFile=(FARPROC1)GetProcAddress( hIcmp,"IcmpCreateFile");
pIcmpCloseHandle=(FARPROC2)GetProcAddress( hIcmp,"IcmpCloseHandle");
pIcmpSendEcho =(FARPROC3)GetProcAddress( hIcmp,"IcmpSendEcho" );
hIP = pIcmpCreateFile();
I.Ttl=isAsync;
pIcmpSendEcho(hIP,*dwIPAddr,0,0,&I,&E,sizeof(E),8000 );
d=E.Address;
phostent = gethostbyaddr((char *)&d,4,PF_INET);
sprintf(aa,"gethostbyaddr %p",phostent );
if ( phostent  != 0 )
strcpy(aa,phostent->h_name);
else
strcpy(aa,"no name");
//wsprintf(aa,"RTT: %dms,  TTL: %d",E.RoundTripTime,E.Options.Ttl );
pIcmpCloseHandle( hIP );
FreeLibrary( hIcmp );
WSACleanup();
SendMessage(W,WM_USER+1,0,0);
sprintf(bb,"%d..",isAsync);
MessageBox(0,"native_AviPlayer_stop",bb,0);
return TRUE;
}
#define NP_EXPORT
NPNetscapeFuncs* g_pNavigatorFuncs = NULL;
BOOL WINAPI DllEntryPoint( HINSTANCE  hinstDLL,DWORD  fdwReason,LPVOID  lpvReserved){	return TRUE;}
JRIGlobalRef Private_GetJavaClass(void)
{
    jref clazz = NPP_GetJavaClass();
    if (clazz) {
		JRIEnv* env = NPN_GetJavaEnv();
		return JRI_NewGlobalRef(env, clazz);
    }
    return NULL;
}
static NPPluginFuncs* g_pluginFuncs;
NPError WINAPI NP_EXPORT  NP_Initialize(NPNetscapeFuncs* pFuncs)
{
    g_pNavigatorFuncs = pFuncs; // save it for future reference 
    g_pluginFuncs->javaClass          = Private_GetJavaClass();
    return NPP_Initialize();
}
NPError WINAPI NP_EXPORT  NP_Shutdown(){    return NPERR_NO_ERROR;}
JRIEnv* NPN_GetJavaEnv(void)
{
        return g_pNavigatorFuncs->getJavaEnv();
}
jref NPN_GetJavaPeer(NPP instance)
{
        return g_pNavigatorFuncs->getJavaPeer(instance);
}
NPError NPP_Initialize(void){    return NPERR_NO_ERROR;}
void NPP_Shutdown(void){}
NPError NP_LOADDS NPP_New(NPMIMEType pluginType,                NPP instance,                uint16 mode,                int16 argc,                char* argn[],                char* argv[],                NPSavedData* saved){   	return NPERR_NO_ERROR;}
NPError NP_LOADDS NPP_Destroy(NPP instance, NPSavedData** save){    return NPERR_NO_ERROR;}
NPError NP_LOADDS NPP_NewStream(NPP instance,              NPMIMEType type,              NPStream *stream,               NPBool seekable,              uint16 *stype){    return NPERR_NO_ERROR;}
void NP_LOADDS NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname){}
int32 NP_LOADDS NPP_WriteReady(NPP instance, NPStream *stream){    return 0xffff;  }
int32 NP_LOADDS NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer){       return len;}
NPError NP_LOADDS NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason){    return NPERR_NO_ERROR;}
void NP_LOADDS NPP_Print(NPP instance, NPPrint* printInfo){}
NPError WINAPI NP_EXPORT  NP_GetEntryPoints(NPPluginFuncs* pFuncs)
{
    pFuncs->version       = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
    pFuncs->newp          = NPP_New;
    pFuncs->destroy       = NPP_Destroy;
    pFuncs->setwindow     = NPP_SetWindow;
    pFuncs->newstream     = NPP_NewStream;
    pFuncs->destroystream = NPP_DestroyStream;
    pFuncs->asfile        = NPP_StreamAsFile;
    pFuncs->writeready    = NPP_WriteReady;
    pFuncs->write         = NPP_Write;
    pFuncs->print         = NPP_Print;
    pFuncs->event         = NULL;       /// reserved 
    g_pluginFuncs             = pFuncs;
    return NPERR_NO_ERROR;
}




AviPlayer.java

import netscape.plugin.Plugin;
public class AviPlayer extends Plugin
{
public native boolean stop(int isAsync);
}



NPAVI32.Def
LIBRARY   NPAVI

CODE	  PRELOAD MOVEABLE DISCARDABLE
DATA	  PRELOAD SINGLE

EXPORTS
	NP_GetEntryPoints   @1
	NP_Initialize       @2
	NP_Shutdown         @3


NPAVI32.RC

//Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS


#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE DISCARDABLE 
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE DISCARDABLE 
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE DISCARDABLE 
BEGIN
    "#include ""npavi32.rc2""  // non-Microsoft Visual C++ edited resources\r\n"
    "\r\n"
    "#define _AFX_NO_SPLITTER_RESOURCES\r\n"
    "#define _AFX_NO_OLE_RESOURCES\r\n"
    "#define _AFX_NO_TRACKER_RESOURCES\r\n"
    "#define _AFX_NO_PROPERTY_RESOURCES\r\n"
    "#include ""afxres.rc""  // Standard components\r\n"
    "\0"
END

/////////////////////////////////////////////////////////////////////////////
#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 1,0,0,1
 PRODUCTVERSION 1,0,0,1
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x2L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904e4"
        BEGIN
            VALUE "CompanyName", "Netscape Communications\0"
            VALUE "FileDescription", "NPAVI32 MFC Extension DLL\0"
            VALUE "FileExtents", "avi|avi\0"
            VALUE "FileOpenName", "Video for Windows (*.avi)|Video for Windows (*.avi)\0"
            VALUE "FileVersion", "1, 0, 0, 1\0"
            VALUE "InternalName", "NPAVI32\0"
            VALUE "LegalCopyright", "Copyright Netscape Communications \251 1995\0"
            VALUE "MIMEType", "video/x-msvideo|video/msvideo\0"
//            VALUE "MIMEType", "video/x-msvideo\0"
            VALUE "OriginalFilename", "NPAVI32.DLL\0"
            VALUE "ProductName", "NPAVI32 Dynamic Link Library\0"
            VALUE "ProductVersion", "1, 0, 0, 1\0"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1252
    END
END



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#include "npavi32.rc2"  // non-Microsoft Visual C++ edited resources

#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#include "afxres.rc"  // Standard components

/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED


npavi32.rc2
//
// PLUGTEST.RC2 - resources Microsoft Visual C++ does not edit directly
//

#ifdef APSTUDIO_INVOKED
	#error this file is not editable by Microsoft Visual C++
#endif //APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
// Add manually edited resources here...

/////////////////////////////////////////////////////////////////////////////

Resource.h

//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by npavi32.rc
//

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        129
#define _APS_NEXT_COMMAND_VALUE         32771
#define _APS_NEXT_CONTROL_VALUE         1000
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif


AviTest.htm
<html>
<body>
<center>
<h1>Avi Plugin test using JavaScript</h1>
(You'll need to change this demo and supply your own AVI
movie).
<embed  name=avi SRC="books.avi"  WIDTH=300 HEIGHT=100>
<hr>
<form>
<input type=button onclick="document.avi.stop(parseInt(form.editSeek.value))"
                value=stop>
<input  name=editSeek  type=text value=0  size=10>
</form>
</center>
</body>
</html>

Download the Source Code


Have any suggestions, comments, ideas, cracked code, feedback. Feel free to get in touch with us.

Move back to the Vijay Mukhi's Technology Cornucopia Page to learn more about the other new Internet Technologies.


Vijay Mukhi's Computer Institute
VMCI, B-13, Everest Building, Tardeo, Bombay 400 034, India
E-mail:vmukhi@giasbm01.vsnl.net.in Tel : 91-22-496 4335 /6/7/8/9 Fax : 91-22-307 28 59
http://www.vijaymukhi.com