 |
 |
Navigation Services to get FILE* -- how?
|
 |
|
 |
|
Forum Regular
Join Date: Aug 2001
Location: PA
Status:
Offline
|
|
I'd like to use the Apple Carbon Navigation Services in a C program to obtain a regular stdio file pointer (FILE *). This would allow me to keep most of my application platform independent with standard ANSI C code.
I need it to:
1) open an input (preexisting) file with Navigation Services, and to
2) open an output (normally nonexistant but with a check to be sure) file with Navigation Services.
Is there some example code around so I don't have to reinvent the wheel?
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by warnergt:
<strong>I'd like to use the Apple Carbon Navigation Services in a C program to obtain a regular stdio file pointer (FILE *). This would allow me to keep most of my application platform independent with standard ANSI C code.
I need it to:
1) open an input (preexisting) file with Navigation Services, and to
2) open an output (normally nonexistant but with a check to be sure) file with Navigation Services.
Is there some example code around so I don't have to reinvent the wheel?</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Take a look at <a href="http://developer.apple.com/techpubs/macosx/Carbon/Files/NavigationServices/Prog_Navigation_Services/index.html" target="_blank">this link</a> for info on using Nav Services. You can follow their sample code, but you should use FSRef instead of FSSpec in order to support long file names. Anywhere you see FSSpec, replace it with an FSRef, and replace typeFSS with typeFSRef. Then you can use this to translate the FSRef into a path:
FSRef myRef;
UInt8 path[PATH_MAX];
FILE* file;
FSRefMakePath(&myRef, path, PATH_MAX);
file = fopen((char*)path, "r");
To go the other way:
char* myPath;
FSRef resultRef;
FSPathMakeRef(myPath, &resultRef, NULL);
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jun 2000
Location: Pasadena
Status:
Offline
|
|
been looking for this for like 2 days...just didn't occur to me to look here 'til now  thx! made my life much easier! now i can output the path to a text box in my program! 
|
|
G4/450, T-bird 1.05GHz, iBook 500, iBook 233...4 different machines, 4 different OSes...(9, 2k, X.1, YDL2.2 respectively) PiA to maintain...
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jun 2000
Location: Pasadena
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by bewebste:
<strong>Take a look at <a href="http://developer.apple.com/techpubs/macosx/Carbon/Files/NavigationServices/Prog_Navigation_Services/index.html" target="_blank">this link</a> for info on using Nav Services. You can follow their sample code, but you should use FSRef instead of FSSpec in order to support long file names. Anywhere you see FSSpec, replace it with an FSRef, and replace typeFSS with typeFSRef. Then you can use this to translate the FSRef into a path:
FSRef myRef;
UInt8 path[PATH_MAX];
FILE* file;
FSRefMakePath(&myRef, path, PATH_MAX);
file = fopen((char*)path, "r");
To go the other way:
char* myPath;
FSRef resultRef;
FSPathMakeRef(myPath, &resultRef, NULL);</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I have a few questions regarding that...
first, PATH_MAX is a constant? what should the value be generally speaking...(FSRefMakePath asks for UInt32)
Also, how do i use theString = CFSTR((char*)path)? I get an "illegal function call" error and a "parse error before string constant"  (more directly, I'm trying to do SetControlData(stringOutBox, kControlEntireControl, kControlEditTextCFStringTag, sizeof(CFStringRef), &
theString); with no luck...
|
|
G4/450, T-bird 1.05GHz, iBook 500, iBook 233...4 different machines, 4 different OSes...(9, 2k, X.1, YDL2.2 respectively) PiA to maintain...
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status:
Offline
|
|
PATH_MAX should be declared in syslimits.h, one of the standard C headers. Under OS X, it's defined as 1024 - don't know its value under OS 9. You basically just need a sufficiently large buffer to hold any path that might come up.
The CFSTR() macro only works with string constants, like CFSTR("foo") as opposed to CFSTR(myCString). You can create a CFString from a C string using CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8).
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by bewebste:
<strong>PATH_MAX should be declared in syslimits.h, one of the standard C headers. Under OS X, it's defined as 1024 - don't know its value under OS 9. You basically just need a sufficiently large buffer to hold any path that might come up.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Actually, 1024 is a bit small on a modern OS with the possibility of using multi-byte characters in paths. I think Apple should expand it a bit.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Oct 2000
Location: Somerville, MA and San Jose, CA
Status:
Offline
|
|
Definitinely check out the MoreFilesX sample code at developer.apple.com. It'll take care of a lot of these goodies for you. Very good stuff.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|