Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: JDirect to Carbon example?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JDirect to Carbon example?



At 9:31 AM -0700 5/30/2001, Steve Poole wrote:
Could some kind soul provide me with an example of using JDirect on X to call Carbon routines?

We showed one example during the Mac OS X Technologies for Java Applications session at WWDC that looked something like this:
-----
import com.apple.mrj.jdirect.Linker;

public class MemoryFunctions {
private static Object linkage = new Linker(MemoryFunctions.class);
private static final String JDirect_MacOSX = "/System/Library/Frameworks/CoreServices.framework/CoreServices";

// Ptr NewPtr(Size size);
public static native int NewPtr(int size);
}
-----

Before long (hopefully the start of next week) we'll be posting a rather large collection of JDirect code as part of the MacFile and MacApplication classes that were demoed in that session.

Until that time, I'd also suggest that you take a look at <http://developer.apple.com/technotes/tn/tn2002.html> and/or use /Developer/Applications/JavaBrowser to look at the com.apple.mrj.macos.generated.* classes on Mac OS X. Don't reference those directly in your code -- as we have in the past, we reserve the right to change what's in there from release to release -- but in looking at them you'll get a better sense of how to write JDirect code.

Finally, and this was also mentioned in that WWDC session, you need to wrap this around every call to Carbon in your code to ensure that you don't crash due to Carbon not being re-entrant:

import com.apple.mrj.macos.carbon.CarbonLock;

....
try {
CarbonLock.acquire();
SomeCarbonFunctions.SomeCallToCarbon();
} finally {
CarbonLock.release();
}

Hope this helps,
Eric

--
Eric Albert email@hidden
Intern, Java Classes


References: 
 >JDirect to Carbon example? (From: Steve Poole <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.