我有一个 C++ 自定义操作项目。我有两个功能,RegProductName
和GetProductName
。
我打电话RegProductName
,它有三种可能的结果。我在 if 语句中有这些,如果它是结果 1 或结果 2,那么我调用我的第二个函数GetProductName
,但我似乎无法让它工作。谁能给我一个从另一个函数调用一个函数的例子吗?
extern "C" UINT __stdcall RegProductName(MSIHANDLE hInstall)
{
AssertSz(FALSE, "debug here");
DebugBreak();
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
char szProductName[MAX_PATH];
hr = WcaInitialize(hInstall, "RegProductName");
ExitOnFailure(hr, "Failed to initialize");
WcaLog(LOGMSG_STANDARD, "Initialized.");
strcpy(szProductName, Orc_Get_Product_Name());
if(szProductName == "ORCHESTRATOR")
{
GetProductName();
}
else if (szProductName == "CORAL")
{
GetProductName();
}
else
{
MsiSetProperty(hInstall, "PRODUCTNAME", szProductName);
}
LExit:
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
return WcaFinalize(er);
}
错误是“当我将鼠标悬停在函数调用中时,参数太少GetProductName();
extern "C" UINT __stdcall GetProductName(MSIHANDLE hInstall)
{
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
DWORD Ret;
CHAR *Section = "General";
CHAR szBuffer[MAX_PATH];
CHAR szProductIniFile[MAX_PATH];
char lpszString[MAX_PATH];
int lplValue;
hr = WcaInitialize(hInstall, "GetProductName");
ExitOnFailure(hr, "Failed to initialize");
WcaLog(LOGMSG_STANDARD, "Initialized.");
TCHAR* szValueBuf = NULL;
DWORD cchValueBuf = 0;
UINT uiStat = MsiGetProperty(hInstall, TEXT("TEMPFOLDER"), TEXT(""), &cchValueBuf);
if (ERROR_MORE_DATA == uiStat)
{
++cchValueBuf;
szValueBuf = new TCHAR[cchValueBuf];
if (szValueBuf)
{
uiStat = MsiGetProperty(hInstall, TEXT("TEMPFOLDER"), szValueBuf, &cchValueBuf);
}
}
if (ERROR_SUCCESS != uiStat)
{
if (szValueBuf != NULL)
delete[] szValueBuf;
return ERROR_INSTALL_FAILURE;
}
strcpy(szProductIniFile,szValueBuf);
Ret = strlen(szProductIniFile);
if(szProductIniFile[Ret-1] != '\\')
strcat(szProductIniFile,"\\");
strcat(szProductIniFile, "Product.ini");
Ret = GetPrivateProfileString(Section, // Section Title [General]
"PRODUCT_NAME", // Entry
"Orchestrator", // Default Value
szBuffer, // Address of buffer to read to
MAX_PATH, // Length of buffer
szProductIniFile); // .ini file name
if (strlen(szBuffer) == 0)
strcpy(szBuffer, "ORCHESTRATOR");
if (strlen(szBuffer) >= 3 && (stricmp(szBuffer+strlen(szBuffer)-3,"DEM") == 0))
lplValue = 1;
else
lplValue = 0;
MsiSetProperty(hInstall, "PRODUCTNAME", szBuffer);
LExit:
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
return WcaFinalize(er);
}