Re: User friendly machine name (gestaltUserVisibleMachineName?) [SOLVED]
Re: User friendly machine name (gestaltUserVisibleMachineName?) [SOLVED]
- Subject: Re: User friendly machine name (gestaltUserVisibleMachineName?) [SOLVED]
- From: "Clark S. Cox III" <email@hidden>
- Date: Mon, 2 Jun 2003 16:29:19 -0400
On Monday, Jun 2, 2003, at 15:00 US/Eastern, Rolf wrote:
Hi all,
I have found the solution. Thanks for pointing me in the right
direction. Here is a class method that returns the Machine Name:
+(NSString * )machineName {
SInt32 gestaltReturnValue;
// Fetch machine name as pointer to PStr255 (Pascal String:
Byte0=length, Byte1..255=Characters)
if (!Gestalt(gestaltUserVisibleMachineName, &gestaltReturnValue)) {
return [NSString stringWithCString: (char *)gestaltReturnValue
+ 1];
} else {
return @"Unknown";
}
}
Use this instead (pascal strings aren't NUL-terminated, result of
cString is undefined for non-ASCII characters):
+(NSString * )machineName
{
Str255 gestaltReturnValue;
// Fetch machine name as pointer to PStr255 (Pascal String:
Byte0=length, Byte1..255=Characters)
if (!Gestalt(gestaltUserVisibleMachineName,
(SInt32)&gestaltReturnValue))
{
return [(NSString*)CFStringCreateWithPascalString(NULL,
gestaltReturnValue, kCFStringEncodingMacRoman) autorelease];
} else {
return @"Unknown";
}
}
--
http://homepage.mac.com/clarkcox3/
email@hidden
Clark S. Cox, III
_______________________________________________
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.