Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-dev] SWT: Calling Windows GDI+ function that requires a parameter passed by reference

Hi, I need to call this GDI+ function from the SWT code:

	void TextureBrush(
	  Image                 *image,
	  const Rect &          dstRect,
	  const ImageAttributes *imageAttributes
	);

For calling, I allocate a new Rect object:

long rect = Gdip.Rect_new(0, 0, Gdip.Image_GetWidth(image2),
	Gdip.Image_GetHeight(image2));
long brush = Gdip.TextureBrush_new(image2, rect, attrib);
if (brush == 0) SWT.error(SWT.ERROR_NO_HANDLES);
Gdip.Rect_delete(rect);


The definition in class Gdip is:

/**
 * @method flags=new
 * @param image cast=(Image *)
 * @param rect cast=(Rect *)
 * @param attribs cast=(ImageAttributes *)
 */
public static final native long TextureBrush_new(long image, long rect,
long attribs);


The generated JNI code is (I added the pointer dereference of arg1
manually to make it compile):

#ifndef NO_TextureBrush_1new__JJJ
extern "C" JNIEXPORT jlong JNICALL
Gdip_NATIVE(TextureBrush_1new__JJJ)(JNIEnv *env, jclass that, jlong
arg0, jlong arg1, jlong arg2);
JNIEXPORT jlong JNICALL Gdip_NATIVE(TextureBrush_1new__JJJ)
	(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jlong arg2)
{
	jlong rc = 0;
	Gdip_NATIVE_ENTER(env, that, TextureBrush_1new__JJJ_FUNC);
	rc = (jlong)new TextureBrush((Image *)arg0, *((Rect *)arg1),
(ImageAttributes *)arg2);
	Gdip_NATIVE_EXIT(env, that, TextureBrush_1new__JJJ_FUNC);
	return rc;
}
#endif

Of course editing manually is not an acceptable solution.

Is there any idiom to pass parameters from Java to C++ functions that
require references?

Stefan


Back to the top