1 #ifndef __cpPipelineEditor__MainHelper__h__
2 #define __cpPipelineEditor__MainHelper__h__
5 #include <QApplication>
7 // -------------------------------------------------------------------------
8 #define cpPipelineEditor_Main( _window_class_ ) \
9 int main( int argc, char* argv[] ) \
11 QApplication a( argc, argv ); \
12 _window_class_ w( argc, argv ); \
14 return( a.exec( ) ); \
17 // -------------------------------------------------------------------------
24 # include <shellapi.h>
26 // -------------------------------------------------------------------------
27 namespace cpPipelineEditor
31 class Win32CommandLineConverter
34 std::unique_ptr< char*[ ] > argv_;
35 std::vector< std::unique_ptr< char[ ] > > storage_;
38 Win32CommandLineConverter( )
40 LPWSTR cmd_line = GetCommandLineW( );
42 LPWSTR* w_argv = CommandLineToArgvW( cmd_line, &argc );
43 argv_ = std::unique_ptr< char*[ ] >( new char*[ argc ] );
44 storage_.reserve( argc );
45 for( int i = 0; i < argc; ++i )
47 storage_.push_back( ConvertWArg( w_argv[ i ] ) );
48 argv_[ i ] = storage_.back( ).get( );
55 return( static_cast< int >(storage_.size( ) ) );
59 return( argv_.get( ) );
61 static std::unique_ptr< char[ ] > ConvertWArg( LPWSTR w_arg )
63 int size = WideCharToMultiByte(
64 CP_UTF8, 0, w_arg, -1, nullptr, 0, nullptr, nullptr
66 std::unique_ptr< char[ ] > ret( new char[ size ] );
68 CP_UTF8, 0, w_arg, -1, ret.get( ), size, nullptr, nullptr
76 // -------------------------------------------------------------------------
77 # define cpPipelineEditor_MainComplement \
78 int CALLBACK WinMain( HINSTANCE i, HINSTANCE p, LPSTR c, int s ) \
80 cpPipelineEditor::Win32CommandLineConverter cmd_line; \
81 return( main( cmd_line.argc( ), cmd_line.argv( ) ) ); \
84 # define cpPipelineEditor_MainComplement
87 #endif // __cpPipelineEditor__MainHelper__h__