JNI GetAWT

scaryman Messages postés 492 Date d'inscription vendredi 30 janvier 2004 Statut Membre Dernière intervention 16 mai 2007 - 9 janv. 2006 à 21:45
Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 - 10 janv. 2006 à 18:23
bonjour
voila j'essaie de récupérer la fenetre java de facon native avec ce code-ci trouvé sur internet :

#include "Hello.h"
#include
#include "jawt_md.h"

JNIEXPORT void JNICALL
Java_Hello_flashWindow(
JNIEnv * env, jobject canvas, jobject component, jboolean boo) {

JAWT awt;
JAWT_DrawingSurface* ds;
JAWT_DrawingSurfaceInfo* dsi;
JAWT_Win32DrawingSurfaceInfo* dsi_win;
jboolean result;

jint lock;

// Get the AWT
awt.version = JAWT_VERSION_1_4;
result = JAWT_GetAWT(env, &awt);
assert(result != JNI_FALSE);
// Get the drawing surface
ds = awt.GetDrawingSurface(env, component);
if(ds == NULL)
return;
// Lock the drawing surface
lock = ds->Lock(ds);
assert((lock & JAWT_LOCK_ERROR) == 0);

// Get the drawing surface info
dsi = ds->GetDrawingSurfaceInfo(ds);

// Get the platform-specific drawing info
dsi_win =
(JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;

//code here

// Free the drawing surface info
ds->FreeDrawingSurfaceInfo(dsi);
// Unlock the drawing surface
ds->Unlock(ds);
// Free the drawing surface
awt.FreeDrawingSurface(ds);
}

il y a un problème à la méthode JAWT_GetAWT parce que je recois l'erreur suivante :
undefined reference to `_imp__JAWT_GetAWT@8'

est-ce un problème d'inclusion de bibliothèques ou autres??

merci

3 réponses

Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 111
9 janv. 2006 à 22:54
Salut,



Bon pour quand tu utilise jawt_md.h tu ne dois pas le faire comme tu fais mais plus comme suit

#include <jawt_md.h>



et pour ne pas obtenir d'erreur dans ta ligne de compilation tu ajoute
le repertoire include de java exemple chez moi (sous linux mais le
principe est le meme à ce niveau)



mes options de compile ressemble à :



-I/opt/sun-jdk-1.5.0.05/include -I/opt/sun-jdk-1.5.0.05/include/linux
-O3 -march=pentium-m -pipe -fomit-frame-pointer -g3 -Wall -c
-fmessage-length=0




WORA
0
scaryman Messages postés 492 Date d'inscription vendredi 30 janvier 2004 Statut Membre Dernière intervention 16 mai 2007 12
10 janv. 2006 à 17:07
salut
merci Twinuts mais si j'enlève cette ligne là le code compile bien et j'ai bien mis ces dossiers dans les inclusions du compilateur.
Pourrais-tu essayer de compiler ce code chez toi pou voir si ca marche.
Voici le code du fichier Hello.h :
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Hello */

#ifndef _Included_Hello
#define _Included_Hello
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Hello
* Method: flashWindow
* Signature: (Ljava/awt/Component;Z)V
*/
JNIEXPORT void JNICALL Java_Hello_flashWindow
(JNIEnv *, jclass, jobject, jboolean);

#ifdef __cplusplus
}
#endif
#endif

dis-moi quoi.
merci
0
Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 111
10 janv. 2006 à 18:23
Salut,



Vu que je ne suis pas sous windaube je ne peux tester le code de flashWindow....


Sinon bon admettons les projets suivant



TestJniJava

->src

->Test.java

->Hello.java

TestJniC //créer en librairie dynamique

->src

->Hello.h

->Hello.c



le fichier Test.java :

public class Test {



public Test(){

new Hello().setVisible(true);

}



public static void main(String[] args) {

javax.swing.SwingUtilities.invokeLater(new Runnable(){

public void run(){

new Test();

}

});

}

}





le fichier Hello.java



import java.awt.Dimension;



import javax.swing.JFrame;



public class Hello extends JFrame{



static{


System.load("hello");


}



public Hello(){

super("Test JNI");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setSize(new Dimension(300, 300));

setLocationRelativeTo(null);

}



public native void flashWindow(boolean value);

}



tu compile et tu nous fais un ptit javah -jni Hello.class

si tu es sous eclipse voici le build.xml

<?xml version="1.0"?>



<target name="default">

<javah destdir="../TestJniC/src/" force="yes" classpath="bin">



<class name="Hello"/>

</javah>

</target>





maintenant le projet C



le fichier Hello.h



/* DO NOT EDIT THIS FILE - it is machine generated */

#include <jni.h>

/* Header for class Hello */



#ifndef _Included_Hello

#define _Included_Hello

#ifdef __cplusplus

extern "C" {

#endif

/* Inaccessible static: focusLog */

/* Inaccessible static: log */

#undef Hello_FOCUS_TRAVERSABLE_UNKNOWN

#define Hello_FOCUS_TRAVERSABLE_UNKNOWN 0L

#undef Hello_FOCUS_TRAVERSABLE_DEFAULT

#define Hello_FOCUS_TRAVERSABLE_DEFAULT 1L

#undef Hello_FOCUS_TRAVERSABLE_SET

#define Hello_FOCUS_TRAVERSABLE_SET 2L

/* Inaccessible static: focusTraversalKeyPropertyNames */

/* Inaccessible static: LOCK */

/* Inaccessible static: dbg */

/* Inaccessible static: isInc */

/* Inaccessible static: incRate */

#undef Hello_TOP_ALIGNMENT

#define Hello_TOP_ALIGNMENT 0.0f

#undef Hello_CENTER_ALIGNMENT

#define Hello_CENTER_ALIGNMENT 0.5f

#undef Hello_BOTTOM_ALIGNMENT

#define Hello_BOTTOM_ALIGNMENT 1.0f

#undef Hello_LEFT_ALIGNMENT

#define Hello_LEFT_ALIGNMENT 0.0f

#undef Hello_RIGHT_ALIGNMENT

#define Hello_RIGHT_ALIGNMENT 1.0f

#undef Hello_serialVersionUID

#define Hello_serialVersionUID -7644114512714619750LL

/* Inaccessible static: metrics */

/* Inaccessible static: _00024assertionsDisabled */

#undef Hello_serialVersionUID

#define Hello_serialVersionUID 4613797578919906343LL

/* Inaccessible static: dbg */

#undef Hello_INCLUDE_SELF

#define Hello_INCLUDE_SELF 1L

#undef Hello_SEARCH_HEAVYWEIGHTS

#define Hello_SEARCH_HEAVYWEIGHTS 1L

/* Inaccessible static: serialPersistentFields */

/* Inaccessible static: _00024assertionsDisabled */

/* Inaccessible static: systemSyncLWRequests */

#undef Hello_OPENED

#define Hello_OPENED 1L

/* Inaccessible static: nameCounter */

#undef Hello_serialVersionUID

#define Hello_serialVersionUID 4497834738069338734LL

/* Inaccessible static: dbg */

/* Inaccessible static: locationByPlatformProp */

#undef Hello_DEFAULT_CURSOR

#define Hello_DEFAULT_CURSOR 0L

#undef Hello_CROSSHAIR_CURSOR

#define Hello_CROSSHAIR_CURSOR 1L

#undef Hello_TEXT_CURSOR

#define Hello_TEXT_CURSOR 2L

#undef Hello_WAIT_CURSOR

#define Hello_WAIT_CURSOR 3L

#undef Hello_SW_RESIZE_CURSOR

#define Hello_SW_RESIZE_CURSOR 4L

#undef Hello_SE_RESIZE_CURSOR

#define Hello_SE_RESIZE_CURSOR 5L

#undef Hello_NW_RESIZE_CURSOR

#define Hello_NW_RESIZE_CURSOR 6L

#undef Hello_NE_RESIZE_CURSOR

#define Hello_NE_RESIZE_CURSOR 7L

#undef Hello_N_RESIZE_CURSOR

#define Hello_N_RESIZE_CURSOR 8L

#undef Hello_S_RESIZE_CURSOR

#define Hello_S_RESIZE_CURSOR 9L

#undef Hello_W_RESIZE_CURSOR

#define Hello_W_RESIZE_CURSOR 10L

#undef Hello_E_RESIZE_CURSOR

#define Hello_E_RESIZE_CURSOR 11L

#undef Hello_HAND_CURSOR

#define Hello_HAND_CURSOR 12L

#undef Hello_MOVE_CURSOR

#define Hello_MOVE_CURSOR 13L

#undef Hello_NORMAL

#define Hello_NORMAL 0L

#undef Hello_ICONIFIED

#define Hello_ICONIFIED 1L

#undef Hello_MAXIMIZED_HORIZ

#define Hello_MAXIMIZED_HORIZ 2L

#undef Hello_MAXIMIZED_VERT

#define Hello_MAXIMIZED_VERT 4L

#undef Hello_MAXIMIZED_BOTH

#define Hello_MAXIMIZED_BOTH 6L

/* Inaccessible static: nameCounter */

#undef Hello_serialVersionUID

#define Hello_serialVersionUID 2673458971256075116LL

#undef Hello_EXIT_ON_CLOSE

#define Hello_EXIT_ON_CLOSE 3L

/* Inaccessible static: defaultLookAndFeelDecoratedKey */



/*

* Class: Hello

* Method: flashWindow

* Signature: (Z)V

*/

JNIEXPORT void JNICALL Java_Hello_flashWindow

(JNIEnv *, jobject, jboolean);



#ifdef __cplusplus

}

#endif

#endif



le fichier hello.c



#include "Hello.h"

#include <stdio.h>



/*

* Class: Hello

* Method: flashWindow

* Signature: (Z)V

*/

JNIEXPORT void JNICALL Java_Hello_flashWindow

(JNIEnv *env, jobject classHello, jboolean value){



//ici tu tape le code que tu veux :)

//exemple




fprintf(stdout, "le boolean java = %d\n", value);


}



tu compile exemple chez moi

gcc -I/opt/sun-jdk-1.5.0.05/include
-I/opt/sun-jdk-1.5.0.05/include/linux -O3 -march=pentium-m -pipe
-fomit-frame-pointer -g3 -Wall -c -fmessage-length=0 -osrc/Hello.o
../src/Hello.c



pour pas se casser tu prend ta lib tu l'as place ici /opt/sun-jdk-1.5.0.05/jre/lib/i386

(sinon tu rajoute le chemin de ta lib dans la variable LD_LIBRARY_PATH (tu l'as creer si besoin))


tu lance ton appli java et c'est bon



WORA
0
Rejoignez-nous