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