]> Creatis software - cpPlugins.git/blob - appli/PipelineEditor/main.cxx
First dump for version 0.1.0
[cpPlugins.git] / appli / PipelineEditor / main.cxx
1 #include "PipelineEditor.h"
2 #include <cstdlib>
3 #include <QApplication>
4
5 // -------------------------------------------------------------------------
6 int main( int argc, char* argv[] )
7 {
8   QApplication a( argc, argv );
9   PipelineEditor w( argc, argv, NULL );
10   w.show( );
11
12   return( a.exec( ) );
13 }
14
15 // -------------------------------------------------------------------------
16 #ifdef _WIN32
17
18 #include <memory>
19 #include <vector>
20 #include <windows.h>
21 #include <shellapi.h>
22
23 /**
24  */
25 class Win32CommandLineConverter
26 {
27 private:
28   std::unique_ptr< char*[ ] > argv_;
29   std::vector< std::unique_ptr< char[ ] > > storage_;
30
31 public:
32   Win32CommandLineConverter( )
33     {
34       LPWSTR cmd_line = GetCommandLineW( );
35       int argc;
36       LPWSTR* w_argv = CommandLineToArgvW( cmd_line, &argc );
37       argv_ = std::unique_ptr< char*[ ] >( new char*[ argc ] );
38       storage_.reserve( argc );
39       for( int i = 0; i < argc; ++i )
40       {
41         storage_.push_back( ConvertWArg( w_argv[ i ] ) );
42         argv_[ i ] = storage_.back( ).get( );
43
44       } // rof
45       LocalFree( w_argv );
46     }
47   int argc( ) const
48     {
49       return( static_cast< int >(storage_.size( ) ) );
50     }
51   char** argv( ) const
52     {
53       return( argv_.get( ) );
54     }
55   static std::unique_ptr< char[ ] > ConvertWArg( LPWSTR w_arg )
56     {
57       int size = WideCharToMultiByte(
58         CP_UTF8, 0, w_arg, -1, nullptr, 0, nullptr, nullptr
59         );
60       std::unique_ptr< char[ ] > ret( new char[ size ] );
61       WideCharToMultiByte(
62         CP_UTF8, 0, w_arg, -1, ret.get( ), size, nullptr, nullptr
63         );
64       return( ret );
65     }
66 };
67
68 int CALLBACK WinMain(
69   HINSTANCE hInstance,
70   HINSTANCE hPrevInstance,
71   LPSTR lpCmdLine,
72   int nCmdShow
73   )
74 {
75   Win32CommandLineConverter cmd_line;
76   return( main( cmd_line.argc( ), cmd_line.argv( ) ) );
77 }
78
79 #endif
80
81 // eof - $RCSfile$