1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

example for LSOpenApplication()

Discussion in 'Mac Programming' started by chidambaram, Sep 18, 2008.

  1. macrumors member

    #1
    hi all,

    i am working in carbon c application(Mac OS 10.4.7).

    give one example for LSOpenApplication().

    How to use FSRef() in LSOpenApplication()?

    Thanks in advance
     
  2. Moderator emeritus

    kainjow

    #2
    FSRefs are Carbon's way of working with files. You need to create one first with a known path (which should point to a .app):

    Code:
    OSStatus status = noErr;
    FSRef ref;
    
    status = FSPathMakeRef((const UInt8 *)path, &ref, NULL);
    if (status != noErr) {
        printf("Couldn't get FSRef\n");
        return status;
    }
    Then once you have the FSRef setup you can call LSOpenApplication:

    Code:
    LSApplicationParameters params = {0, kLSLaunchDefaults, &ref, NULL, NULL, NULL};
    return LSOpenApplication(&params, NULL);
     
  3. macrumors member

    #3
    thanks for ur reply sir.

    its not working for me

    what to give in the path variable. I given the entire address directly

    i tried as

    OSStatus status = noErr;
    FSRef ref;

    const char path[] = "/Users/laserwords/Desktop/one.indd";

    status = FSPathMakeRef((const UInt8 *)path, &ref, NULL);

    LSApplicationParameters params = {0, kLSLaunchDefaults, &ref, NULL, NULL, NULL};

    LSOpenApplication(&params, NULL);

    what error i made here?
     
  4. Moderator emeritus

    kainjow

    #4
    I'm pretty sure it only works with .app applications (which are bundles). It's like opening something in Finder. You can't double-click an executable in the Finder and launch it, you have to do it via the command line.

    So if one.indd is just a plain executable you need to use another method to launch it. There might be Carbon ways of doing it, but you could probably just use standard POSIX functions for that.
     
  5. macrumors member

    #5
    ya sir its working fine for applications.....

    thanks for ur reply...
     

Share This Page