Get path to user's "Application Support" folder
I need to get the path to the user's "Application Support" folder, where I intend to do some operations using Boost's file-system library. I tried just using "~/Library/Application Support/", but Boost doesn't seem to recognize it.
~ is a shell thing.
You should use NSSearchPathForDirectoriesInDomains to find the folder.
You should use NSSearchPathForDirectoriesInDomains to find the folder.
Thank you.
Now, most of my project is in C++. I've tried writing a function in Objective C that uses a plain C interface (as in, it doesn't have any Cocoa parameters or return values) but I keep getting linker errors when I try to use the function in C++ code.
Now, most of my project is in C++. I've tried writing a function in Objective C that uses a plain C interface (as in, it doesn't have any Cocoa parameters or return values) but I keep getting linker errors when I try to use the function in C++ code.
did you try
extern "C"
{
// C code
}
?
extern "C"
{
// C code
}
?
That did the trick. I forgot about the thing with Obj. C being a strict superset of C. Thank you.
Update
I'm still getting a few problems though. I'm trying to copy the path to a c-string (since C++ can't use NSString). However, the path seems to get cut short, and I end up with "/Users/<my username>/Library/Application Suppor" (note the lack of 't').
This is my function. The path is meant to be stored in the string pointed to by path_dbptr.
Update
I'm still getting a few problems though. I'm trying to copy the path to a c-string (since C++ can't use NSString). However, the path seems to get cut short, and I end up with "/Users/<my username>/Library/Application Suppor" (note the lack of 't').
This is my function. The path is meant to be stored in the string pointed to by path_dbptr.
Code:
int getApplicationDataPath(char **path_dbptr)
{
int result = FALSE;
NSString *destinationPath;
NSArray *allPaths
= NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,
NSUserDomainMask, TRUE);
if ([allPaths count] > 0)
{
destinationPath = [allPaths objectAtIndex:0];
*path_dbptr = (char *)malloc([destinationPath
lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
if ([destinationPath getCString:*path_dbptr
maxLength:[destinationPath
lengthOfBytesUsingEncoding:NSUTF8StringEncoding]
encoding:NSUTF8StringEncoding])
{
result = TRUE;
}
}
return result;
}
Remember that C strings are null-terminated. Instead of just copying (length) bytes, you'll need to copy (length + 1) bytes.
Since when was "Fred" a placeholder variable?
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Drawing a path in-game | GregX999 | 3 | 2,995 |
Dec 1, 2010 07:16 AM Last Post: GregX999 |
|
| Path Finding | bwalters | 22 | 9,308 |
Mar 27, 2006 11:36 AM Last Post: Blacktiger |
|
| file path from NavReplyRecord? | frac707 | 2 | 2,803 |
Mar 2, 2005 05:14 AM Last Post: Hog |
|

