Re: Calling an Objective-C function from C++?
Re: Calling an Objective-C function from C++?
- Subject: Re: Calling an Objective-C function from C++?
- From: Dave Zarzycki <email@hidden>
- Date: Tue, 31 Jan 2012 14:01:05 -0800
Howard,
If you don't want to rename your .cpp file to .mm, then you can just tell Xcode to ignore the file extension and always compile as Objective-C++. Then your C++ code can call Objective-C code natively when compiling for Mac OS X / iOS.
davez
On Jan 31, 2012, at 11:31 AM, Howard Moon <email@hidden> wrote:
> Hi all,
>
> How does one call a Cocoa function from C++ code?
>
> I've got an existing .cpp file that leverages the vstgui framework, which includes support for Cocoa in the underlying layers. However, vstgui does not support dialogs or alerts. My code already supports native Windows dialogs/alerts, and Carbon windows/alerts, as needed, and I'd like to add support for Cocoa when my audio plug-in is compiled as 64-bit on the Mac.
>
> One of my current functions is something like this:
>
> void MyObj::showAlert( char* text, char* caption )
> {
> #ifdef WIN32
> // calls ShowMessage
> #else
> // calls CreateStandardAlert and RunStandardAlert
> #endif
> }
>
> I'd like to add the ability to support Cocoa, by adding a .mm/.h file with the Cocoa code to display an NSAlert, and call it from here when the preprocessor symbol MAC_COCOA is defined. I've created the Cocoa files, but how can I include and call into that code from my .cpp file? Simply adding either #import or #include of my new .h file causes many many errors, even though the .mm file itself compiles fine.
>
> Anyone know of a very simple example showing what I need to do here? All the examples I find so far show making the call from a .mm file in the first place, but I can't do that because my code is also compiled for 32-bit Carbon (and Windows). How do I call from a .cpp file into a .mm file?
>
> Thanks,
> Howard
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please 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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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