Post

Replies

Boosts

Views

Activity

Reply to Xcode custom working directory ignored
Now it's getting really weird. If I add an OpenPanel in the application code and use that to select a file when the application runs, a subsequent call to fopen will successfully open the file! If the OpenPanel cancel button is pressed without selecting that file, or if a different file is selected, then fopen will return NULL.
Jul ’21
Reply to Xcode custom working directory ignored
If I change the current directory using either NSFileManager:changeCurrentDirectoryPath or _wchdir, both functions succeed, but a following call to get the current directory fails. If getcwd is used, it produces errno 1 (operation not permitted), and NFFileManager.currentDicrectoryPath is equal to nil. The Xcode project location is in a subfolder of the user Documents directory.
Jul ’21
Reply to Rename main() function?
Several years later, I have the answer to this. In the main header file I added this definition: #ifdef __APPLE__ #define main cppmain #endif Declare your C++ main function just like normal and the compiler will internally rename it to "cppmain". And then in main.mm I have the real main function: #undef main int main(int argc, const char* args) {     return NSApplicationMain(); } #define main cppmain And in AppDelegate.mm the C++ main function is called with arguments passed to it: ` extern int cppmain(int argc, const char* argv[]); - (void)applicationDidFinishLaunching:(NSNotification )aNotification {     int argc = _NSGetArgc();     char argv = _NSGetArgv();     cppmain(argc, (const char*)argv);     [NSApp terminate:self]; } ` As a result all our existing examples work just fine with the normal main() function declared in C++: https://www.ultraengine.com/learn/CPP/CreateTreeView
Topic: Programming Languages SubTopic: General Tags:
Jun ’21
Reply to Xcode custom working directory ignored
Now it's getting really weird. If I add an OpenPanel in the application code and use that to select a file when the application runs, a subsequent call to fopen will successfully open the file! If the OpenPanel cancel button is pressed without selecting that file, or if a different file is selected, then fopen will return NULL.
Replies
Boosts
Views
Activity
Jul ’21
Reply to Xcode custom working directory ignored
Additionally, I have observed that fopen fails to read a file in the target directory. To me, this indicates some security feature may be blocking the program from accessing the hard drive, even though I have full disk access enabled for this application.
Replies
Boosts
Views
Activity
Jul ’21
Reply to Xcode custom working directory ignored
I enabled full disk access to the application in the security and privacy system settings, but it seems to make no difference.
Replies
Boosts
Views
Activity
Jul ’21
Reply to Xcode custom working directory ignored
If I change the current directory using either NSFileManager:changeCurrentDirectoryPath or _wchdir, both functions succeed, but a following call to get the current directory fails. If getcwd is used, it produces errno 1 (operation not permitted), and NFFileManager.currentDicrectoryPath is equal to nil. The Xcode project location is in a subfolder of the user Documents directory.
Replies
Boosts
Views
Activity
Jul ’21
Reply to Rename main() function?
Nice, I can't edit my answer above to fix the formatting.
Topic: Programming Languages SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Rename main() function?
Several years later, I have the answer to this. In the main header file I added this definition: #ifdef __APPLE__ #define main cppmain #endif Declare your C++ main function just like normal and the compiler will internally rename it to "cppmain". And then in main.mm I have the real main function: #undef main int main(int argc, const char* args) {     return NSApplicationMain(); } #define main cppmain And in AppDelegate.mm the C++ main function is called with arguments passed to it: ` extern int cppmain(int argc, const char* argv[]); - (void)applicationDidFinishLaunching:(NSNotification )aNotification {     int argc = _NSGetArgc();     char argv = _NSGetArgv();     cppmain(argc, (const char*)argv);     [NSApp terminate:self]; } ` As a result all our existing examples work just fine with the normal main() function declared in C++: https://www.ultraengine.com/learn/CPP/CreateTreeView
Topic: Programming Languages SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’21