]> git.tdb.fi Git - libs/core.git/blob - source/core/windows/main.cpp
Add move semantics to Variant
[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
6 using namespace std;
7 using namespace Msp;
8
9 int main(int argc, char **argv)
10 {
11         return Msp::Application::run(argc, argv);
12 }
13
14 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/)
15
16         int argc        = 0;
17         LPWSTR *argv_w = CommandLineToArgvW(GetCommandLineW(), &argc);
18
19         unsigned max_size = 0;
20         for(int i=0; i<argc; ++i)
21                 max_size += wcslen(argv_w[i])*4+1;
22
23         char *argv_buf = new char[max_size+(argc+1)*sizeof(char *)];
24         char **argv = reinterpret_cast<char **>(argv_buf);
25         char *argv_ptr = argv_buf+(argc+1)*sizeof(char *);
26         for(int i=0; i<argc; ++i)
27         {
28                 argv[i] = argv_ptr;
29                 string arg(reinterpret_cast<char *>(argv_w[i]), wcslen(argv_w[i])*2);
30                 arg = StringCodec::transcode<StringCodec::Utf16Le, StringCodec::Utf8>(arg);
31                 copy(arg.begin(), arg.end(), argv_ptr);
32                 argv_ptr += arg.size();
33                 *argv_ptr++ = 0;
34         }
35
36         LocalFree(argv_w);
37         int exit_code = Msp::Application::run(argc, argv, hInstance);
38         delete[] argv_buf;
39         return exit_code;
40 }