WinMain関数でmain関数のargc,argvを得る
// 空ファイルを作成する。 #include <windows.h> #include <tchar.h> #include <stdio.h> int WINAPI _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd ) { if (__argc <= 1) return 0; // コマンドライン引数の数 TCHAR* file = __targv[1]; // コマンドライン引数。 // charなら__argv // wchar_tなら__wargv // TCHARなら__targv FILE* fp = _tfopen(file, _T("r")); if (fp == NULL) { // ない場合だけ作る fp = _tfopen(file, _T("w")); } fclose(fp); }
lpCmdLineだといちいち文字列解析しないといけないので、__argvのが便利。