Index: src/OFApplication.h ================================================================== --- src/OFApplication.h +++ src/OFApplication.h @@ -161,20 +161,16 @@ * * @param status The status with which the application will terminate */ + (void)terminateWithStatus: (int)status; -/*! - * @brief Sets argc and argv. - * - * You should not call this directly, but use OF_APPLICATION_DELEGATE instead! - * - * @param argc The number of arguments - * @param argv The argument values - */ -- (void)setArgumentCount: (int*)argc - andArgumentValues: (char**[])argv; +- (void)OF_setArgumentCount: (int*)argc + andArgumentValues: (char**[])argv; +#ifdef _WIN32 +- (void)OF_setArgumentCount: (int)argc + andWideArgumentValues: (wchar_t*[])argv; +#endif /*! * @brief Gets args and argv. * * @param argc A pointer where a pointer to argc should be stored Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -33,10 +33,13 @@ #if defined(__MACH__) && !defined(OF_IOS) # include #elif defined(_WIN32) # include + +extern int _CRT_glob; +extern void __wgetmainargs(int*, wchar_t***, wchar_t***, int, int*); #elif !defined(OF_IOS) extern char **environ; #endif static OFApplication *app = nil; @@ -70,13 +73,23 @@ int of_application_main(int *argc, char **argv[], Class cls) { OFApplication *app = [OFApplication sharedApplication]; id delegate = [[cls alloc] init]; +#ifdef _WIN32 + wchar_t **wargv, **wenvp; + int wargc, si = 0; +#endif + + [app OF_setArgumentCount: argc + andArgumentValues: argv]; - [app setArgumentCount: argc - andArgumentValues: argv]; +#ifdef _WIN32 + __wgetmainargs(&wargc, &wargv, &wenvp, _CRT_glob, &si); + [app OF_setArgumentCount: wargc + andWideArgumentValues: wargv]; +#endif [app setDelegate: delegate]; [app run]; @@ -259,19 +272,17 @@ } return self; } -- (void)setArgumentCount: (int*)argc_ - andArgumentValues: (char***)argv_ +- (void)OF_setArgumentCount: (int*)argc_ + andArgumentValues: (char***)argv_ { +#ifndef _WIN32 void *pool = objc_autoreleasePoolPush(); int i; - [programName release]; - [arguments release]; - argc = argc_; argv = argv_; programName = [[OFString alloc] initWithCString: (*argv)[0] @@ -282,13 +293,37 @@ [arguments addObject: [OFString stringWithCString: (*argv)[i] encoding: OF_STRING_ENCODING_NATIVE]]; [arguments makeImmutable]; + + objc_autoreleasePoolPop(pool); +#else + argc = argc_; + argv = argv_; +#endif +} + +#ifdef _WIN32 +- (void)OF_setArgumentCount: (int)argc_ + andWideArgumentValues: (wchar_t**)argv_ +{ + void *pool = objc_autoreleasePoolPush(); + int i; + + programName = [[OFString alloc] initWithUTF16String: argv_[0]]; + arguments = [[OFMutableArray alloc] init]; + + for (i = 1; i < argc_; i++) + [arguments addObject: + [OFString stringWithUTF16String: argv_[i]]]; + + [arguments makeImmutable]; objc_autoreleasePoolPop(pool); } +#endif - (void)getArgumentCount: (int**)argc_ andArgumentValues: (char****)argv_ { *argc_ = argc;