Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

JNI (Win32), GetComponent, GC

Thread view: 
Manuel Leclerc - 15 May 2006 12:03 GMT
Hi, and sorry for the poor english.

I create a native (win32) thread in a java process (by code injection,
with the CreateRemoteThread-LoadLibrary trick).

Next, I use the folowing APIs :
- JNI_GetCreatedJavaVMs
- AttachCurrentThread
- JAWT_GetAWT

Next, I use a win32 API (EnumWindows) and obtain a Windows Handle (type
HWND) belonging to the Java process.

Finally, I use GetComponent and get a "jobject" corresponding to the
'hwnd'.

It works: I am able to call some java methods.

My question:

What about the GC? Should I call some "free" method when I no longer
need to keep the "jobject" ?

--
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"
Gordon Beaton - 15 May 2006 13:01 GMT
> Should I call some "free" method when I no longer need to keep the
> "jobject" ?

Possibly...

In native code that that does not *return* to Java, you must
explicitly notify the garbage collector about unused object
references.

In native code that does return to Java, objects will automatically
become eligible for gc when they return, although if you'e creating
lots of objects locally you may need to notify gc before returning.

To notify the garbage collector, use DeleteLocalRef().

Note that the normal reachability rules also apply, so for references
passed outside the native method (in calls to other Java methods or in
return values etc), the objects won't actually become eligible for
collection until they are no longer reachable from those other places.

You can also use a combination of PushLocalFrame() and PopLocalFrame()
around a section of a native method, to get behaviour similar to that
of invoking a method (Push..) and returning from it (Pop...). The
garbage collector gets notified about any objects created within the
local frame when PopLocalFrame() is called.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.