嗨,我正在使用该strtok
功能将句子分成两部分。我似乎无法弄清楚如何保存两个单独的值,该函数在我只需要知道存储值的那一刻就成功地拆分了句子。谢谢
extern "C" UINT __stdcall GetProductName(MSIHANDLE hInstall)
{
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
char szProductName[MAX_PATH];
TCHAR* szValueBuf = NULL;
DWORD cchValueBuf = 0;
char * pch;
std::vector<std::string> parts;
hr = WcaInitialize(hInstall, "GetProductName");
ExitOnFailure(hr, "Failed to initialize");
WcaLog(LOGMSG_STANDARD, "Initialized.");
UINT uiStat = MsiGetProperty(hInstall, TEXT("ProductName"), TEXT(""), &cchValueBuf);
if (ERROR_MORE_DATA == uiStat)
{
++cchValueBuf;
szValueBuf = new TCHAR[cchValueBuf];
if (szValueBuf)
{
uiStat = MsiGetProperty(hInstall, TEXT("ProductName"), szValueBuf, &cchValueBuf);
}
}
if (ERROR_SUCCESS != uiStat)
{
if (szValueBuf != NULL)
delete[] szValueBuf;
return ERROR_INSTALL_FAILURE;
}
if (Orc_Create_Product_Key(szValueBuf))
hr = S_OK;
else
hr = ERROR_INSTALL_FAILURE;
pch = strtok (szValueBuf," ");
parts.push_back(pch);
while (pch != NULL)
{
pch = strtok (NULL, " ");
parts.push_back(pch);
}
strcpy(szProductName, szValueBuf);
hr = MsiSetProperty(hInstall, "PRODUCTNAME", szProductName);
ExitOnFailure(hr, "failed to set PRODUCTNAME");
LExit:
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
return WcaFinalize(er);
}
如您所见,第一个值将是szProductName
,但我也需要获得第二个值。