public class zzz
{
public static void main(String s[])
{
MessageBox(0,"Message Box successfully called","In Java",0);
}
/** @dll.import("USER32") */
static native int MessageBox(int i, String j, String k, int l);
}
zzz.c
#include <windows.h>
_stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l)
{
MessageBox(0,"Message Box successfully called","in C",0);
}
Program 2
zzz.java
public class zzz
{
public static void main(String s[])
{
StringBuffer a = new StringBuffer(512);
GetEnvironmentVariable("PATH",a,513);
System.out.println(a);
}
/** @dll.import("KERNEL32") */
static native int GetEnvironmentVariable(String j, StringBuffer k, int l);
}
zzz.c
#include <windows.h>
_stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l)
{
char a[512];
GetEnvironmentVariable("PATH",a,512);
MessageBox(0,a,"hi",0);
}
Program 3
import com.ms.win32.*;
public class zzz
{
public static void main(String s[])
{
MEMORYSTATUS m = new MEMORYSTATUS();
GlobalMemoryStatus(m);
System.out.println("Total Physical Memory : "+Integer.toHexString(m.dwTotalPhys));
System.out.println("Total Available Memory : "+Integer.toHexString(m.dwAvailPhys));
System.out.println("Total Page File : "+Integer.toHexString(m.dwTotalPageFile));
System.out.println("Available Page File : "+Integer.toHexString(m.dwAvailPageFile));
System.out.println("Total Virtual Memory : "+ Integer.toHexString(m.dwTotalVirtual));
System.out.println("Available Virtual Memory : "+ Integer.toHexString(m.dwAvailVirtual));
}
/** @dll.import("KERNEL32") */
static native void GlobalMemoryStatus(MEMORYSTATUS m);
}
zzz.c
#include <windows.h>
_stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l)
{
char aa[100];
MEMORYSTATUS m;
GlobalMemoryStatus(&m);
sprintf(aa,"Total Physical Memory : %x ",m.dwTotalPhys);
MessageBox(0,aa,"Total Physical Memory",0);
sprintf(aa,"Available Physical Memory : %x ",m.dwAvailPhys);
MessageBox(0,aa,"Available Physical Memory ",0);
sprintf(aa,"Total Page File: %x ",m.dwTotalPageFile);
MessageBox(0,aa,"Total Page File",0);
sprintf(aa,"Available Page File: %x ",m.dwAvailPageFile);
MessageBox(0,aa,"Available Page File",0);
sprintf(aa,"Total Virtual Memory : %x ",m.dwTotalVirtual);
MessageBox(0,aa,"Total Virtual Memory ",0);
sprintf(aa,"Available Virtual Memory : %x ",m.dwAvailVirtual);
MessageBox(0,aa,"Available Virtual Memory ",0);
}
Program 4
public class zzz
{
public static void main(String s[])
{
int a[] = {0};
int b[] = {0};
int c[] = {0};
int d[] = {0};
GetDiskFreeSpace("c:\\",a,b,c,d);
System.out.println("sectors/cluster = "+a[0]);
System.out.println("bytes/sector = "+b[0]);
System.out.println("free clusters = "+c[0]);
System.out.println("clusters = "+d[0]);
}
/** @dll.import("KERNEL32") */
native static boolean GetDiskFreeSpace(String s, int i[], int j[], int k[], int l[]);
}
zzz.c
#include <windows.h>
_stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l)
{
char aa[100];
int a, b, c, d ;
GetDiskFreeSpace("c:\\",&a,&b,&c,&d);
sprintf(aa,"sectors : %d",a);
MessageBox(0,aa,"hi",0);
sprintf(aa,"bytes/sector : %d",b);
MessageBox(0,aa,"hi",0);
sprintf(aa,"free clusters : %d",c);
MessageBox(0,aa,"hi",0);
sprintf(aa,"clusters : %d",d);
MessageBox(0,aa,"hi",0);
}
Program 5
public class zzz
{
public static void main(String s[])
{
int a[] = {0};
int b[] = {0};
int c[] = {0};
int d[] = {0};
GetDiskFreeSpace("c:\\",a,b,c,d);
System.out.println("sectors/cluster = "+a[0]);
System.out.println("bytes/sector = "+b[0]);
System.out.println("free clusters = "+c[0]);
System.out.println("clusters = "+d[0]);
}
/** @dll.import("KERNEL32") */
native static boolean GetDiskFreeSpace(String s, int i[], int j[], int k[], int l[]);
}
zzz.c
#include <windows.h>
_stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l)
{
char aa[100];
int a, b, c, d ;
GetDiskFreeSpace("c:\\",&a,&b,&c,&d);
sprintf(aa,"sectors : %d",a);
MessageBox(0,aa,"hi",0);
sprintf(aa,"bytes/sector : %d",b);
MessageBox(0,aa,"hi",0);
sprintf(aa,"free clusters : %d",c);
MessageBox(0,aa,"hi",0);
sprintf(aa,"clusters : %d",d);
MessageBox(0,aa,"hi",0);
}
Program 6
import com.ms.dll.*;
public class zzz
{
public static void main(String s[])
{
EnumWindows(new yyy(),0);
}
/** @dll.import("USER32") */
static native boolean EnumWindows(yyy a, int b);
}
class yyy extends Callback
{
public boolean callback(int i, int j)
{
StringBuffer a = new StringBuffer(100);
GetWindowText(i, a, a.capacity() + 1);
System.out.println("Window no :" + Integer.toHexString(i) + "Title :"+a);
return true;
}
/** @dll.import("USER32") */
static native int GetWindowText(int a, StringBuffer b, int c);
}
zzz.c
#include <windows.h>
int _stdcall aaa (unsigned int i,unsigned int j)
{
char aa[100],bb[100];
GetWindowText(i,bb,100);
sprintf(aa,"Window no..%x...Title..%s",i,bb);
MessageBox(0,aa,aa,0);
}
_stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l)
{
EnumWindows(aaa,0);
}
Program 7
import com.ms.win32.*;
import com.ms.dll.*;
/** @dll.import("USER32",auto) */
public class zzz
{
public static void main(String s[])
{
EnumFonts(GetDC(GetDesktopWindow()),null, new yyy(),0);
}
static native int GetDesktopWindow();
static native int GetDC(int h);
/** @dll.import("GDI32") */
static native int EnumFonts(int w, String x, yyy y, int z);
}
class yyy extends Callback
{
public int callback(int a, int b, int c, int d)
{
LOGFONT p=(LOGFONT)DllLib.ptrToStruct(LOGFONT.class,a);
System.out.println(p.lfFaceName);
return 1;
}
}
zzz.c
#include <windows.h>
int _stdcall aaa (unsigned int i,unsigned int j, unsigned int k, unsigned int l)
{
char aa[100];
LOGFONT *f= i;
sprintf(aa,"%s..",f->lfFaceName);
MessageBox(0,aa,aa,0);
}
_stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l)
{
EnumFonts(GetDC(GetDesktopWindow()),0,aaa,0);
}
Program 8
import com.ms.win32.*;
/** @dll.import("KERNEL32",auto) */
public class zzz
{
public static void main(String s[])
{
WIN32_FIND_DATA f = new WIN32_FIND_DATA();
String a = "*.*";
int h = FindFirstFile(a,f);
do
{
System.out.println(f.cFileName);
} while(FindNextFile(h,f));
}
static native int FindFirstFile(String a, WIN32_FIND_DATA b);
static native boolean FindNextFile(int h, WIN32_FIND_DATA b);
}
zzz.c
#include <windows.h>
_stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l)
{
WIN32_FIND_DATA f;
char aa[100];
char s[100] = "*.*";
int h = FindFirstFile(s,&f);
do
{
sprintf(aa,"%s",f.cFileName);
MessageBox(0,aa,"hi",0);
}while(FindNextFile(h,&f));
}
Program 9
import com.ms.dll.DllLib;
/** @dll.import("KERNEL32") */
public class zzz
{
public static void main(String s[])
{
String e[]=abc();
for(int i = 0;i < e.length; i++)
{
System.out.println(e[i]);
}
}
static String[] abc()
{
int v = GetEnvironmentStrings();
int a = v;
int c=0;
String b;
do
{
b=DllLib.ptrToStringAnsi(a);
a+=b.length() + 1;
c++;
}while(b.length() !=0);
c--;
String z[] = new String[c];
a=v;
for(int i=0; i<c; i++)
{
z[i]=DllLib.ptrToStringAnsi(a);
a+=z[i].length()+1;
}
return z;
}
static native int GetEnvironmentStrings();
}
zzz.c
#include <windows.h>
_stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l)
{
int ii;
char aa[100];
char *e = GetEnvironmentStrings();
do
{
strcpy(aa,e);
MessageBox(0,aa,aa,0);
ii=strlen(e);
e=e+ii+1;
} while(aa[0]!= 0);
}
Program 10
import com.ms.win32.*;
import com.ms.dll.*;
/** @dll.import("USER32") */
public class zzz
{
public static void main(String s[])
{
WNDCLASS w = new WNDCLASS();
w.lpszClassName="sonal";
w.hbrBackground = 12;
w.lpfnWndProc = DllLib.addrOf(Root.alloc(new yyy()));
RegisterClass(w);
int b = CreateWindowEx(0,"sonal","Win",win.WS_OVERLAPPEDWINDOW,0,0,0,0,0,0,0,0);
ShowWindow(b,3);
MSG c = new MSG();
while(GetMessage(c,0,0,0))
DispatchMessage(c);
}
static native int RegisterClass(WNDCLASS w);
static native int CreateWindowEx(int a, String b, String c, int d, int e, int f, int g,
int h, int i, int k, int l, int m);
static native int ShowWindow(int a, int b);
static native boolean GetMessage(MSG a, int b, int c, int d);
static native int DispatchMessage(MSG a);
}
/** @dll.import("USER32") */
class yyy extends Callback
{
public int callback(int w, int x, int y, int z)
{
if (x == 2)
PostQuitMessage(0);
if (x == win.WM_LBUTTONDOWN)
System.out.println("Left Mouse Button clicked");
return DefWindowProc(w,x,y,z);
}
static native void PostQuitMessage(int a);
static native int DefWindowProc(int a, int b, int c, int d);
}
zzz.c
#include <windows.h>
WNDCLASS w;
HWND b;
MSG c;
long _stdcall yyy (HWND w, UINT x, WPARAM y, LPARAM z);
_stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l)
{
w.hInstance = i;
w.lpszClassName="sonal";
w.lpfnWndProc = yyy;
w.hbrBackground =GetStockObject(GRAY_BRUSH);
RegisterClass(&w);
b=CreateWindow("sonal","Win",WS_OVERLAPPEDWINDOW,0,0,0,0,0,0,i,0);
ShowWindow(b,3);
while(GetMessage(&c,0,0,0))
DispatchMessage(&c);
}
long _stdcall yyy (HWND w, UINT x, WPARAM y, LPARAM z)
{
if ( x == WM_LBUTTONDOWN)
MessageBox(0,"Left Mouse Button Clicked","hi",0);
if (x == WM_DESTROY)
PostQuitMessage(0);
return DefWindowProc(w,x,y,z);
}
Program 11
import com.ms.dll.*;
import com.ms.com._Guid;
public class zzz
{
public static void main(String s[])
{
_Guid g = CoCreateGuid();
String t = StringFromIID(g);
System.out.println("Copying \"" + t + "\" to clipboard");
int a = GlobalAlloc(GMEM_FIXED|GMEM_DDESHARE,t.length() + 1);
int b= GlobalLock(a);
lstrcpyA(b,t);
GlobalUnlock(a);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(1,a);
CloseClipboard();
}
/** @dll.import("OLE32",ole) */
static native _Guid CoCreateGuid();
/** @dll.import("OLE32",ole) */
static native String StringFromIID(_Guid g);
/** @dll.import("KERNEL32") */
static native int GlobalAlloc(int flags, int cb);
/** @dll.import("KERNEL32") */
static native int GlobalLock(int hglob);
/** @dll.import("KERNEL32") */
static native int GlobalUnlock(int hglob);
/** @dll.import("KERNEL32", ansi) */
static native void lstrcpyA(int hptr, String text);
/** @dll.import("USER32") */
static native boolean OpenClipboard(int hwnd);
/** @dll.import("USER32") */
static native boolean CloseClipboard();
/** @dll.import("USER32") */
static native int SetClipboardData(int fmt, int hData);
/** @dll.import("USER32") */
static native boolean EmptyClipboard();
static final int GMEM_FIXED = 0;
static final int GMEM_DDESHARE = 0x2000;
}
zzz.c
#include <windows.h>
_stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l)
{
GUID g;
unsigned int b;
unsigned int *m;
char t[100];
HGLOBAL a;
CoCreateGuid(&g);
StringFromIID(&g,&m);
WideCharToMultiByte(0,0,m,-1,t,100,0,0);
MessageBox(0,t,t,0);
a=GlobalAlloc(GMEM_FIXED|GMEM_DDESHARE,100);
b=GlobalLock(a);
lstrcpyA(b,t);
GlobalUnlock(a);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(1,a);
CloseClipboard();
MessageBox(0,"End","End",0);
}
Program 12
import com.ms.dll.*;
public class zzz
{
public static void main(String s[])
{
int c = DllLib.systemDefaultCharSize;
System.out.println("hi "+c);
}
}
Program 13
import com.ms.dll.*;
import java.lang.reflect.*;
public class zzz
{
public static void main(String s[])
{
Class c;
String n = s[0];
try
{ c = Class.forName(n);
} catch(Exception e){return;}
DllLib.isStruct(c);
System.out.println("Layout of class \"" + c.getName() + "\"");
Field ff[] = c.getDeclaredFields();
for (int i = 0; i < ff.length; i++) {
Field f = ff[i];
if (DllLib.isStruct(f)) {
int oo = DllLib.offsetOf(f);
System.out.println("+" + oo + ": " + " " + f.getName());
}
}
System.out.println();
System.out.println(" Total size = " + DllLib.sizeOf(c) + " bytes.");
}
}
sss.java
/** @dll.struct() */
class sss
{
int a;
int b;
int c;
int d;
}
java zzz sss
Program 14
import com.ms.dll.*;
public class zzz
{
public static void main(String s[])
{
String v = fff.getVersion(getSystemDirectory() + "\\KERNEL32.DLL");
System.out.println(v);
}
private static String getSystemDirectory()
{
StringBuffer p = new StringBuffer(259);
int cb = GetSystemDirectory(p, 260);
return p.toString();
}
/** @dll.import("KERNEL32") */
private static native int GetSystemDirectory(StringBuffer a, int b);
}
/** @dll.struct() */
class bbb
{
public int iVal;
}
/** @dll.import("VERSION",auto) */
class fff
{
static native int GetFileVersionInfoSize(String s,int b[]);
static native boolean GetFileVersionInfo(String a,int b,int c,byte d[]);
static native boolean VerQueryValue(byte a[],String b,int c[],int d[]);
public static String getVersion(String aa)
{
bbb ppInt;
boolean a;
int b[] = {0};
int c[] = {0};
int d[] = {0};
int e;
e = GetFileVersionInfoSize(aa, c);
byte[] f = new byte[e + 32];
a = GetFileVersionInfo(aa, c[0], e, f);
a = VerQueryValue(f,"\\VarFileInfo\\Translation",
b,d);
ppInt = (bbb)DllLib.ptrToStruct(bbb.class, b[0]);
String g = intToHexString(ppInt.iVal);
String h = "\\StringFileInfo\\" +g.substring(4) +
g.substring(0, 4) +"\\FileVersion";
a = VerQueryValue(f, h, b, d);
return DllLib.ptrToString(b[0]);
}
static String intToHexString(int i)
{
String a = new String("00000000" + Integer.toHexString(i));
a = a.toUpperCase();
return a.substring(a.length() - 8);
}
}
Vijay Mukhi's Computer
Institute
VMCI, B-13, Everest Building, Tardeo, Mumbai 400 034, India
Tel : 91-22-496 4335 /6/7/8/9
Fax : 91-22-307 28 59
e-mail : vmukhi@giasbm01.vsnl.net.in
http://www.vijaymukhi.com