• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Newbie question: getting an object back from just a pointer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Newbie question: getting an object back from just a pointer


  • Subject: Newbie question: getting an object back from just a pointer
  • From: Chris Adamson <email@hidden>
  • Date: Sat, 24 Feb 2007 07:35:59 -0500

This is probably an absolutely pathetic question, but I've been doing Java for a long time and have gotten out of practice with pointers. Googling for answers hasn't worked out either, so...

I'm writing a Java-to-native library to wrap QTKit. At ADC's suggestion, my plan for mapping Java objects to Obj-C objects is to hold onto the pointer to an Obj-C object in the form of a long on the Java side. That way, when I make a call to QTKit, I'll need to pass in the longs of all the relevant QTKit objects.

My problem is recreating Cocoa objects from their pointers.


The following code creates a QTMovie object (the NSURL and NSError are originally packed into an array because I had to use performSelectorOnMainThread:, and thus had to pack my arguments into an array to get them to that selector):


  NSURL* url = (NSURL*) [args objectAtIndex:0];
  NSError* initError = (NSError*) [args objectAtIndex:1];
  QTMovie*  movie = [QTMovie movieWithURL:url error:&initError];

This seems to work, because I NSLog the movie object a few lines later with:

  NSLog (@"Created QTMovie %@ at address %u", movie, &movie);

Which emits sensible output like:

2007-02-24 07:10:43.123 java[6940] Created QTMovie <QTMovie: 0x3f42f0 time scale = 600, duration = 82769, rate = 0.000000, tracks = { 0xb0647c0 0xb064c80 0xb0637d0 0xb064750 }> at address 3221212788

My problem -- and I'm sure this is just me being stupid with pointers, sorry -- is casting that pointer to a QTMovie object, which I'll need to do when I come back from a Java call. I've tried to do so right here as a sort of test:

  // let's just test that, shall we?
  NSLog (@"SelectorHelper re-casting movie...");
  QTMovie* movieTest = (QTMovie*) &movie;
  NSLog (@"Re-cast movie is %@", movieTest);

Unfortunately, this is a crasher, and I never see the second NSLog.

I think I'm either mangling the pointer, or profoundly misunderstanding how to get back to an object, given just its address (i.e., &movie). Unless it's something stupider, like I'm not retaining the movie and it's already gone five lines later?

Thanks in advance...

--Chris


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Newbie question: getting an object back from just a pointer
      • From: Keary Suska <email@hidden>
    • Re: Newbie question: getting an object back from just a pointer
      • From: Steve Christensen <email@hidden>
  • Prev by Date: Batch process fro website
  • Next by Date: Bindings and multiple ArrayControllers
  • Previous by thread: Re: Batch process fro website
  • Next by thread: Re: Newbie question: getting an object back from just a pointer
  • Index(es):
    • Date
    • Thread