]> git.tdb.fi Git - libs/core.git/blob - source/core/windows/main.cpp
Add decorations for things which are considered part of the API
[libs/core.git] / source / core / windows / main.cpp
1 #include <windows.h>
2 #include <msp/stringcodec/utf16.h>
3 #include <msp/stringcodec/utf8.h>
4 #include "application.h"
5 #include "mspcore_api.h"
6
7 using namespace std;
8 using namespace Msp;
9
10 MSPCORE_API int main(int argc, char **argv)
11 {
12         return Msp::Application::run(argc, argv);
13 }
14
15 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/)
16
17         int argc        = 0;
18         LPWSTR *argv_w = CommandLineToArgvW(GetCommandLineW(), &argc);
19
20         unsigned max_size = 0;
21         for(int i=0; i<argc; ++i)
22                 max_size += wcslen(argv_w[i])*4+1;
23
24         char *argv_buf = new char[max_size+(argc+1)*sizeof(char *)];
25         char **argv = reinterpret_cast<char **>(argv_buf);
26         char *argv_ptr = argv_buf+(argc+1)*sizeof(char *);
27         for(int i=0; i<argc; ++i)
28         {
29                 argv[i] = argv_ptr;
30                 string arg(reinterpret_cast<char *>(argv_w[i]), wcslen(argv_w[i])*2);
31                 arg = StringCodec::transcode<StringCodec::Utf16Le, StringCodec::Utf8>(arg);
32                 copy(arg.begin(), arg.end(), argv_ptr);
33                 argv_ptr += arg.size();
34                 *argv_ptr++ = 0;
35         }
36
37         LocalFree(argv_w);
38         int exit_code = Msp::Application::run(argc, argv, hInstance);
39         delete[] argv_buf;
40         return exit_code;
41 }