• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Only one loaded executable...How ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Only one loaded executable...How ?


  • Subject: Re: Only one loaded executable...How ?
  • From: Alex Rice <email@hidden>
  • Date: Wed, 22 Jan 2003 21:00:17 -0700

On Wednesday, January 22, 2003, at 01:31 PM, email@hidden wrote:

CFDataRef myCallback(CFMessagePortRef local, SInt32 msgid, CFDataRef data, void *info)
{
}

int main(...)
{
CFMessagePortRef tMessagePortRef;
Boolean tFreeInfo=FALSE;

tMessagePortRef =CFMessagePortCreateRemote(kCFAllocatordefault, CFSTR("MyTool"));

if (tMessagePortRef!=NULL)
{
// Either the tool is not already running or we're so fast that the tool has not been launched yet

CFRelease(tMessagePortRef);

exit(0);
}

tMessagePortRef =CFMessagePortCreateLocal(kCFAllocatordefault, CFSTR("MyTool"),myCallback,NULL,& tFreeInfo);

Sometimes I find Core Foundation is really hard to understand :-) Here is, I think, similar code using Foundation instead of CF.

#import <Foundation/Foundation.h>
#define PORT_NAME @"MLPortTest"

int main (int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSPortNameServer *pServ = [NSPortNameServer systemDefaultPortNameServer];
if([pServ portForName: PORT_NAME])
{
NSLog(@"instance running already. bye!");
exit(0);
}
NSPort *port = [NSPort port];
[pServ registerPort: port name: PORT_NAME];
[NSThread sleepUntilDate: [NSDate distantFuture]];
[pool release];
return 0;
}

Note; this same method can be used to determine from a Foundation app if an NSApp is running. But the NSApp has to get the port into it's RunLoop somehow. I *think* this is the way; it seems to work:

[[NSRunLoop currentRunLoop] addPort: port forMode: NSConnectionReplyMode];



Alex Rice <email@hidden> | Mindlube Software | http://mindlube.com

what a waste of thumbs that are opposable
to make machines that are disposable -Ani DiFranco
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Only one loaded executable...How ? (From: email@hidden)

  • Prev by Date: Thread Safety and Cocoa
  • Next by Date: Re: Table View Headers Programatically
  • Previous by thread: Re: Only one loaded executable...How ?
  • Next by thread: Re: Only one loaded executable...How ?
  • Index(es):
    • Date
    • Thread