Pracuję nad przetwarzaniem ścieżek kodu w języku C++ i eksperymentowałem z wieloma interfejsami API systemu Windows. Czy istnieje różnica między PathGetArgs
/PathRemoveArgs
a lekko masowanym CommandLineToArgvW
?PathGetArgs/PathRemoveArgs vs. CommandLineToArgvW - czy jest jakaś różnica?
Innymi słowy, oprócz długości/czystości, to jest:
std::wstring StripFileArguments(std::wstring filePath)
{
WCHAR tempPath[MAX_PATH];
wcscpy(tempPath, filePath.c_str());
PathRemoveArgs(tempPath);
return tempPath;
}
inny z tego:
std::wstring StripFileArguments(std::wstring filePath)
{
LPWSTR* argList;
int argCount;
std::wstring tempPath;
argList = CommandLineToArgvW(filePath.c_str(), &argCount);
if (argCount > 0)
{
tempPath = argList[0]; //ignore any elements after the first because those are args, not the base app
LocalFree(argList);
return tempPath;
}
return filePath;
}
i tym
std::wstring GetFileArguments(std::wstring filePath)
{
WCHAR tempArgs[MAX_PATH];
wcscpy(tempArgs, filePath.c_str());
wcscpy(tempArgs, PathGetArgs(tempArgs));
return tempArgs;
}
różne od
std::wstring GetFileArguments(std::wstring filePath)
{
LPWSTR* argList;
int argCount;
std::wstring tempArgs;
argList = CommandLineToArgvW(filePath.c_str(), &argCount);
for (int counter = 1; counter < argCount; counter++) //ignore the first element (counter = 0) because that's the base app, not args
{
tempArgs = tempArgs + TEXT(" ") + argList[counter];
}
LocalFree(argList);
return tempArgs;
}
? Wygląda mi na to, że dostarczam czystszą, prostszą, specjalną implementację analizy składniowej, ale chciałbym wiedzieć, czy są jakieś przypadki narożne, w których interfejsy API będą zachowywać się inaczej.
Wygląda na to, że SHLW-APIs ('Path *') nie robią nic specjalnego na znalezienie pierwszej spacji. Jest to prawdopodobnie tym, o czym w dokumentacji chodzi: "Ta funkcja nie powinna być używana w ogólnych szablonach ścieżek poleceń." * [Heurystyka używana przez 'CommandLineToArgvW'] (http://blogs.msdn.com/b /oldnewthing/archive/2010/09/16/10062818.aspx) wydaje się być [nieco bardziej zaangażowany] (http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx). – IInspectable
+1 za linki do starych nowych rzeczy. – computerfreaker