Professional Web Applications Themes

How to use Cocoa calls in Carbon app? - Mac Programming

I'm sure this is an FAQ, but it seems hard to phrase a query that a search engine can profitably use. I'm using Xcode, have a Carbon app, and just want, inside a function, to use some Cocoa calls for which I already know and understand the API rather than hunt down their equivalents in Carbon. My example here is an Objective-C method that returns an NSImage*, and I want to pass the info to the rest of the Carbon app to display in a window. Any tips on this, or pointers to information? General comments on the long-term feasibility ...

  1. #1

    Default How to use Cocoa calls in Carbon app?

    I'm sure this is an FAQ, but it seems hard to phrase a query that a
    search engine can profitably use. I'm using Xcode, have a Carbon app,
    and just want, inside a function, to use some Cocoa calls for which I
    already know and understand the API rather than hunt down their
    equivalents in Carbon.

    My example here is an Objective-C method that returns an NSImage*, and
    I want to pass the info to the rest of the Carbon app to display in a
    window. Any tips on this, or pointers to information? General comments
    on the long-term feasibility of structuring my app this way?

    Andrew
    Andrew Guest

  2. #2

    Default Re: How to use Cocoa calls in Carbon app?

    In article <google.com>,
    com (Andrew Duncan) wrote:
     
    <http://developer.apple.com/doentation/ReleaseNotes/Cocoa/Objective-C+
    +.html>

    Reinder
    Reinder Guest

  3. #3

    Default Re: How to use Cocoa calls in Carbon app?

    In article <google.com>, Andrew
    Duncan <com> wrote:
     

    Or just do it with Carbon. EG for a .png:

    // ------------------------------------------------------------
    // CreateImageFromPNG [static]
    // ------------------------------------------------------------
    // Caller owns it and must release

    CGImageRef CreateImageFromPNG(CFStringRef inFileName)
    {
    CGImageRef theRef = NULL;

    CFBundleRef theBundle = ::CFBundleGetMainBundle();

    if (theBundle != NULL) {

    CFURLRef theURL = ::CFBundleCopyResourceURL(
    theBundle, inFileName, CFSTR("png"), NULL);

    if (theURL != NULL) {

    CGDataProviderRef theProvider =
    ::CGDataProviderCreateWithURL(theURL);

    if (theProvider != NULL) {

    theRef = ::CGImageCreateWithPNGDataProvider(
    theProvider, NULL, true, kCGRenderingIntentDefault);

    ::CFRelease(theProvider);
    }

    ::CFRelease(theURL);
    }
    }

    return theRef;
    }
    Chris Guest

  4. #4

    Default Re: How to use Cocoa calls in Carbon app?

    In article <google.com>,
    com (Andrew Duncan) wrote:
     

    All you need to do to call Objective C frameworks is to (a) link the
    frameworks into the project, (b) import the appropriate headers, and (c)
    make sure the filename extension is one that the compiler recognizes as
    indicating Objective C (you can't generally use the square-bracket
    method syntax in a ".c" file, though you might finesse it with
    appropriate compiler flags).

    --
    Tom "Tom" Harrington
    Macaroni, Automated System Maintenance for Mac OS X.
    Version 2.0: Delocalize, Repair Permissions, lots more.
    See http://www.atomicbird.com/
    Tom Guest

  5. #5

    Default Re: How to use Cocoa calls in Carbon app?

    dans l'article tph-E19038.13592205052004localhost, Tom Harrington à
    no.spam.dammit.net a écrit le 5/05/04 21:59:
     
    >
    > All you need to do to call Objective C frameworks is to (a) link the
    > frameworks into the project, (b) import the appropriate headers, and (c)
    > make sure the filename extension is one that the compiler recognizes as
    > indicating Objective C (you can't generally use the square-bracket
    > method syntax in a ".c" file, though you might finesse it with
    > appropriate compiler flags).[/ref]

    Unfortunately, I don't think this is enough, because the objective-c runtime
    needs to be initialized.
    I use cocoa with carbon intensively. I have a cocoa nib for the app itself,
    launched by NSApplicationMain.
    Then I start the 'carbon' application through the
    applicationDidFinishLaunching notification.

    Eric

    Eric Guest

  6. #6

    Default Re: How to use Cocoa calls in Carbon app?

    In article <BCBFC8C1.20D46%fr>,
    Eric VERGNAUD <fr> wrote:
     
    >
    > Unfortunately, I don't think this is enough, because the objective-c runtime
    > needs to be initialized. I use cocoa with carbon intensively. I have a cocoa
    > nib for the app itself, launched by NSApplicationMain. Then I start the
    > 'carbon' application through the applicationDidFinishLaunching notification.[/ref]

    The correct way to do this is described in Apple doentation that has been
    posted to this thread, but it's definitely not as simple as To implied.

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

  7. #7

    Default Re: How to use Cocoa calls in Carbon app?

    Miro Jurisic <org> wrote in message news:<mit.edu>... 

    Thanks Miro, but I think this doent describes how Obj-C and C++
    interact, which isn't quite the same thing as how Cocoa and Carbon
    interact. I'd be keeping the different sorts of code completely
    segregated... if I could.

    But of course as soon as you call an Obj-C method from a C++ file, it
    becomes and Obj-C++ file, so there will of necessity be a few "hybrid"
    files.

    Andrew
    Andrew Guest

  8. #8

    Default Re: How to use Cocoa calls in Carbon app?

    Eric VERGNAUD <fr> wrote in message news:<BCBFC8C1.20D46%fr>... 

    This sounds like some of the information I knew I needed, but didn't
    quite know what it was. It sounds like your application is mainly a
    Cocoa app, making some Carbon calls. I'm currently leaning toward a
    Carbon application that makes some Cocoa calls.

    Can you give a few more details about how you have mixed these two
    libraries and runtimes? Thanks for any help you can give.

    Andrew
    Andrew Guest

  9. #9

    Default Re: How to use Cocoa calls in Carbon app?

    In article <google.com>,
    com (Andrew Duncan) wrote:
     

    At this point I am not sure which doent you are talking about, but I was
    talking about
    <http://developer.apple.com/doentation/Cocoa/Conceptual/CarbonCocoaDoc/index.h
    tml>.

    hth

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

  10. #10

    Default Re: How to use Cocoa calls in Carbon app?

    dans l'article google.com, Andrew Duncan
    à com a écrit le 6/05/04 19:17:
     
    >
    > This sounds like some of the information I knew I needed, but didn't
    > quite know what it was. It sounds like your application is mainly a
    > Cocoa app, making some Carbon calls. I'm currently leaning toward a
    > Carbon application that makes some Cocoa calls.
    >
    > Can you give a few more details about how you have mixed these two
    > libraries and runtimes? Thanks for any help you can give.
    >
    > Andrew[/ref]

    Please contact me privately, so I can send you some files.

    Eric

    Eric Guest

  11. #11

    Default Re: How to use Cocoa calls in Carbon app?

    > At this point I am not sure which doent you are talking about, but I was 

    Ah yes, that is a helpful doent, and was pointed out in a different
    thread. The one I thought you meant was the one posted by Reiner
    Verlinde in this thread.

    A
    Andrew Guest

  12. #12

    Default Re: How to use Cocoa calls in Carbon app?

    In article <tph-E19038.13592205052004localhost>,
    Tom Harrington <no.spam.dammit.net> wrote:
     
    >
    > All you need to do to call Objective C frameworks is to (a) link the
    > frameworks into the project, (b) import the appropriate headers, and (c)
    > make sure the filename extension is one that the compiler recognizes as
    > indicating Objective C (you can't generally use the square-bracket
    > method syntax in a ".c" file, though you might finesse it with
    > appropriate compiler flags).[/ref]

    Doesn't he also have to call NSApplicationLoad() or whatever that beast
    was called?

    Wondering,
    -- Uli
    http://www.zathras.de
    Uli Guest

Similar Threads

  1. Replies: 9
    Last Post: February 26th, 11:00 PM
  2. Cocoa in Carbon - weird behaviour
    By Eric VERGNAUD in forum Mac Programming
    Replies: 0
    Last Post: October 1st, 12:22 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139