Re: Trouble accessing Objective-C++ code from a C++ thread
Re: Trouble accessing Objective-C++ code from a C++ thread
- Subject: Re: Trouble accessing Objective-C++ code from a C++ thread
- From: Allan Odgaard <email@hidden>
- Date: Sun, 29 Feb 2004 19:07:47 +0100
On 29. Feb 2004, at 18:32, JoanBa wrote:
I'm completely lost. Any idea ??
huh... a little confused after reading all that stuff ;)
You cannot import ObjectiveC headers or use the bracket method
invocation syntax from a pure C++ file -- either make it a ObjectiveC++
file (no harm in that), or use objc_msgSend to send messages (defined
in objc/objc.h).
When you send an ObjectiveC message, chances are that someone will
allocate temporary objects (which thus goes into the auto release
pool), but by default you only have an auto release pool in the main
thread. So in the thread that needs to send messages, do something
like:
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
...
[pool release];
You cannot send messages from an arbitrary thread to a GUI element in
your application (since the method code would be executed in your
threads context, and AppKit is not thread safe). You can however use
something like NSObject's
performSelectorOnMainThread:withObject:waitUntilDone: to send a message
and have it relayed.
Finally, I think I read somewhere that one had to use NSThread so that
Cocoa would know that the application is multithreaded -- I am not sure
about this bit...
Hope some of the above can give you a hint of where your problem is...
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.