make c function in objc-class know about instance?

  • hi!

    there must be a simple solution, but i just can't see it...

    i'm using some library code which is calling a callback function i
    declared in my class interface.
    now my problem is that the callback function, which is a c-function,
    doesn't even know self.
    i need to declare the callback as a c function, but i want the
    callback function to know about the object.

    (the framework sends strings to my callback function, and i want to
    send them to a textView object.
    but i don't have access to the textView object in the callback
    function.)

    i'm lost.

    any help would be really cool!

    max
    _____________________________________________

    m a x i m i l i a n  m a r c o l l
    http://www.maximilianmarcoll.de

    d i s . p l a y c e
    http://dis.playce.info
  • Create singelton object, if feasible in your case, and access it in
    your C function.

    On 12/30/06, maximilian marcoll <mail...> wrote:
    >
    > hi!
    >
    > there must be a simple solution, but i just can't see it...
    >
    > i'm using some library code which is calling a callback function i
    > declared in my class interface.
    > now my problem is that the callback function, which is a c-function,
    > doesn't even know self.
    > i need to declare the callback as a c function, but i want the
    > callback function to know about the object.
    >
    > (the framework sends strings to my callback function, and i want to
    > send them to a textView object.
    > but i don't have access to the textView object in the callback
    > function.)
    >
    > i'm lost.
    >
    > any help would be really cool!
    >
    > max
    > _____________________________________________
    >
    > m a x i m i l i a n  m a r c o l l
    > http://www.maximilianmarcoll.de
    >
    > d i s . p l a y c e
    > http://dis.playce.info
    >
  • On 31/12/06, maximilian marcoll <mail...> wrote:
    > i'm using some library code which is calling a callback function i
    > declared in my class interface.
    > now my problem is that the callback function, which is a c-function,
    > doesn't even know self.
    > i need to declare the callback as a c function, but i want the
    > callback function to know about the object.

    I asked the same question a while back on the objc-language list, the
    response I got is archived at -
    <http://lists.apple.com/archives/objc-language/2004/Dec/msg00006.html>

    -Phil
  • On Dec 30, 2006, at 4:28 AM, maximilian marcoll wrote:

    >
    > hi!
    >
    > there must be a simple solution, but i just can't see it...
    >
    > i'm using some library code which is calling a callback function i
    > declared in my class interface.
    > now my problem is that the callback function, which is a c-function,
    > doesn't even know self.
    > i need to declare the callback as a c function, but i want the
    > callback function to know about the object.

    Pass self to the function when it is called. Most callbacks based
    APIs provide a way to supply a context to pass to the callback when
    it is called. If the library code doesn't supply such a means IMHO it
    is broken.

    -Shawn
  • thank you!!

    max

    On Dec 30, 2006, at 1:55 PM, Gurmit Teotia wrote:

    > Create singelton object, if feasible in your case, and access it in
    > your C function.

    _____________________________________________

    m a x i m i l i a n  m a r c o l l
    http://www.maximilianmarcoll.de

    d i s . p l a y c e
    http://dis.playce.info
  • Your callback function _ought_ to take a void* parameter, which you are able
    to pass in when you set up the callback, so that you can use it to pass
    through whatever data you want, such as the pointer to the Obj-C instance,
    and cast it back to the proper value when you get it. If the library does
    not do that, then it's a broken design.

    --
    Scott Ribe
    <scott_ribe...>
    http://www.killerbytes.com/
    (303) 722-0567 voice
previous month december 2006 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Go to today