// CarbonProcessManager.cpp
#include <iostream>
#import <Carbon/Carbon.h>
#import <Foundation/Foundation.h>
#define PROGNAME "cpmtest"
void c2pstrcpy(Str255 dst, const char* src)
{
size_t len = std::min<size_t>(strlen(src), 255);
dst[0] = len;
memcpy(&dst[1], src, len);
}
int
main(int argc, char **argv)
{
OSErr err;
Str255 path;
FSRef fsRef;
LaunchParamBlockRec launchParams;
if (argc != 2) {
printf("usage: %s <full application path>\n", PROGNAME);
// exit(1);
}
c2pstrcpy(path,"Macintosh HD:Applications:Chess.app:Contents:MacOs:Chess");
NSString* pPath=[NSString stringWithUTF8String:"Macintosh HD:Applications:Thunder.app:Contents:MacOS:Thunder"];
NSURL* fileURL=[NSURL URLWithString:[pPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *URL1 = [NSURL fileURLWithPath:@"/Applications/Thunder.app/Contents/MacOS/Thunder" isDirectory:NO];
err = CFURLGetFSRef((__bridge CFURLRef)URL1, &fsRef);
if (err == noErr) {
printf("failed to make FS spec for application (error %d).\n", err);
exit(1);
}
// the extendedBlock constant specifies that we are using the fields that
// follow this field in the structure
launchParams.launchBlockID = extendedBlock;
// length of the fields following this field (again, use a constant)
launchParams.launchEPBLength = extendedBlockLen;
// launch control flags
// we want the existing program to continue, and not terminate
// moreover, we want the function to determine the Finder flags itself
launchParams.launchControlFlags = launchContinue + launchNoFileFlags;
// FSSpec for the application to launch
launchParams.launchAppRef = &fsRef;
// no parameters
launchParams.launchAppParameters = NULL;
err = LaunchApplication(&launchParams);
if (err != noErr) {
printf("failed to launch application (error %d).\n", err);
exit(1);
}
printf("main: launched application, PSN = %lu_%lu\n",
launchParams.launchProcessSN.highLongOfPSN,
launchParams.launchProcessSN.lowLongOfPSN);
printf("main: continuing\n");
exit(0);
}
mac os x 通过Carbon Process Manager启动应用程序
原创
©著作权归作者所有:来自51CTO博客作者土匪猿的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
jenkins通过脚本启动java应用
本文简单简单介绍怎么通过jenkins来调用shell脚本启动java脚本。
html/xml shell -
通过VsPhere体验MAC OS X
使用ESX 4体验MAC OS X
职场 体验 休闲 VsPhere MAC OS X