Hvad er årsagen til at man ikke kan låse JAWT_DrawingSurface ?
Jeg har behov for at få fat i HWND for et vindue i en applet og til det formål anvender jeg SUN's awt native interface via JNI i et c++-program.Denne metode er valgt da man tilsyneladende fra og med java 1.4 ikke længere kan gøre det direkte i java.
Jeg har lavet følgende c++ program:
// tm_Mycanvas.cpp: implementation of the tm_Mycanvas class.
//
//////////////////////////////////////////////////////////////////////
#include "jawt_md.h"
#include "tm_MyCanvas.h"
/*
* Class: tm_MyCanvas
* Method: getHwnd
* Signature: ()I
*/
extern "C" {
JNIEXPORT jint JNICALL Java_tm_MyCanvas_getHwnd
(JNIEnv* env, jobject canvas)
{
JAWT awt;
JAWT_DrawingSurface* ds;
JAWT_DrawingSurfaceInfo* dsi;
JAWT_Win32DrawingSurfaceInfo* dsi_win32;
jint lock;
HWND hwnd;
/* get the AWT */
awt.version = JAWT_VERSION_1_3;
if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
printf("AWT not found\n");
return 0;
}
/* Get the drawing surface */
ds = awt.GetDrawingSurface (env,canvas);
if (ds == NULL){
printf("NULL drawingsurface\n");
return 1;
}
/* Lock the drawing surface */
lock = ds->Lock(ds);
if ((lock & JAWT_LOCK_ERROR) != 0) {
printf("Error locking surface\n");
awt.FreeDrawingSurface(ds);
return 2;
}
/* Get the drawing surface info */
dsi = ds->GetDrawingSurfaceInfo (ds);
if (dsi == NULL){
printf("ERROR getting drawing surface info\n");
ds->Unlock;
awt.FreeDrawingSurface(ds);
return 3;
}
/* get the platform-specific drawing info */
dsi_win32 = (JAWT_Win32DrawingSurfaceInfo*) dsi->platformInfo;
/* gethwnd */
hwnd = dsi_win32->hwnd;
/* Free the drawing surfacce info*/
ds->FreeDrawingSurfaceInfo(dsi);
/* Unlock the drawing surface */
ds->Unlock(ds);
/* Free the drawing surfacce */
awt.FreeDrawingSurface(ds);
/* return the hwnd */
return (int)hwnd;
}
}
Problemet er at når jeg kalder det fra mit javaprogram ryger jeg ind i en JAWT_LOCK_ERROR og jeg får returneret 2.
Jeg har ikke rigtig kunnet finde noget på nettet om mulige årsager JAWT_LOCK_ERROR.
Hvad kan være årsagen til fejlen ?
Findes der en lettere måde at få fat i HWND i java 1.4 ?
