Writing an ObcJ function/calling it from C++

Moderator
Posts: 1,140
Joined: 2005.07
Post: #16
Well, close: you need to compile it as ObjectiveC++. (with the .mm extension, as OSC said)
Quote this message in a reply
Jones
Unregistered
 
Post: #17
Ack, I seem to be receiving many suggestions at once. Shock

I can either use the temporary solution, which sounds easy and will be quick or I can come up with a more organized permanent solution right now. I'd rather do the latter, because this is code I plan to use later to produce other standard error messages.

Quote:Also, don't use StandardAlert; it's ancient, nasty, and deprecated. There are better ways of doing it (just say whether you want Cocoa or Carbon code).

Deprecation is what I want to avoid in the this case. Cocoa is preferable because it will work a lot better in the future, I hope.

When I started this thread I hoped there would be a very simple function for displaying dialogs like the windows MessageBox() command (gotta love how easy that is Rasp) but for Mac OS X. Something that didn't require use of Cocoa classes or instances (or simply: something that didn't require a whole lot of extra learning for a simple dialog). I'll have to admit that I approached this with a feeling of "It's just a message box darnit!". But if this is unavoidable then I feel I'd be better off learning some Cocoa anyway and coming back to this later once I've got a better understanding of this language.

And Cookie, I'm not sure I'd call my attitude towards compiler errors 'Cavalier'. Admittedly I may not understand all of them as well as many others here, but they are not something I regard offhandedly. Sad
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #18
Code:
+ (NSAlert *)alertWithMessageText:(NSString *)messageTitle defaultButton:(NSString *)defaultButtonTitle alternateButton:(NSString *)alternateButtonTitle otherButton:(NSString *)otherButtonTitle informativeTextWithFormat:(NSString *)informativeTextWithFormat, ...

That is,

Code:
[NSAlert alertWithMessageText:@"Message" defaultButton:@"OK" alternateButton:@"Cancel" otherButton:nil informativeTextWithFormat:@"You made %d programming errors", 17];

If you have C strings, +[NSString stringWithUTF8String:] is your friend.

If you're doing this outside the Cocoa event loop, you will need

Code:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// ... run your alert here
[pool release];

To avoid the "you're leaking" warnings you quoted earlier.
Quote this message in a reply
Jones
Unregistered
 
Post: #19
Well, that seems like a quick, clean and safe way to do this. Smile

Thank you very much OSC. Smile
Quote this message in a reply
Jones
Unregistered
 
Post: #20
If I drop in OSC's code it compiles, but never displays a message.

You know, I should have just stuck with OpenGL rendered error messages. It would've caused much less trouble. LOL

Thanks for your help, but I've asked for too much assistance for this simple problem already. I shall find another solution.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #21
You need to call -[NSAlert runModal] on your alert instance to display it...
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Writing libraries vs writing apps. Najdorf 8 4,997 Nov 13, 2008 02:32 PM
Last Post: backslash
  Better way of calling a function in another class? brush 5 4,411 Jun 12, 2008 11:23 PM
Last Post: AnotherJake
  Problem drawing pictures after calling RunApplicationEventLoop petr6534 5 4,592 Feb 8, 2005 06:58 PM
Last Post: petr6534