LoginSignup
1
1

More than 5 years have passed since last update.

MFCアプリでgoogle-gflagsを使用する

Posted at

google-gflagsのビルド、ヘッダの配置、ライブラリのリンクは説明を割愛。

コマンドラインの解析処理にargc, argvを渡す必要があるが、MFCの場合main関数がないため受け取ることができない。
CWinAppクラスのm_lpCmdLineメンバに引数の文字列があるが、この形式ではgoogle-gflagsに渡すことはできない。

ところが、実はargc/argvの前にアンダーバーを2つつけたグローバル変数が存在し、プログラム内から参照することができる。したがって下記の1行をInitInstanceの中にいれておけば、プログラム中の好きな個所でオプション引数を参照できるようになる。

// コマンドラインオプションの解析
google::ParseCommandLineFlags(&__argc, &__argv, true);
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1