拆分可执行文件path和参数

我需要能够分割命令中的可执行文件path参数

Windows轻松处理以下内容:

“notepad.exe C:\ testfile.txt”

“记事本c:\ testfolder \ versioninfo.txt”

“C:\ Windows \ notepad.exe”“C:\ test folder \ versioninfo.txt”

rundll“C \ Windows \ somelibrary.dll”

任何人都有一段代码来parsing这样的string?

谢谢。

以前我用过这样的东西:

char* lpCmdLine = ...; char* lpArgs = lpCmdLine; // skip leading spaces while(isspace(*lpArgs)) lpArgs++; if(*lpArgs == '\"') { // executable is quoted; skip to first space after matching quote lpArgs++; int quotes = 1; while(*lpArgs) { if(isspace(*lpArgs) && !quotes) break; if(*lpArgs == '\"') quotes = !quotes; } } else { // executable is not quoted; skip to first space while(*lpArgs && !isspace(*lpArgs)) lpArgs++; } // TODO: skip any spaces before the first arg