PDA

View Full Version : example for LSOpenApplication()




chidambaram
Sep 18, 2008, 05:37 AM
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



kainjow
Sep 18, 2008, 11:08 AM
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):

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:

LSApplicationParameters params = {0, kLSLaunchDefaults, &ref, NULL, NULL, NULL};
return LSOpenApplication(&params, NULL);

chidambaram
Sep 19, 2008, 03:16 AM
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?

kainjow
Sep 19, 2008, 05:29 AM
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.

chidambaram
Sep 19, 2008, 05:39 AM
ya sir its working fine for applications.....

thanks for ur reply...