0

I have a C++ Custom Action Project. I have two functions, RegProductName and GetProductName.

I call RegProductName and it has three possible outcomes. I have these in an if statement that if it is outcome 1 or outcome 2 then i call my second function GetProductName but i can't seem to get it working. Can anyone give me an example of calling one function from another please?

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);
}

The error is "Too few arguments in function call when i hover over 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);
}
Natalie Carr
  • 3,707
  • 3
  • 34
  • 68

5 Answers5

2

This does not compare the string content:

if(szProductName == "ORCHESTRATOR")

either use strcmp() or use std::string and ==:

if(szProductName == std::string("ORCHESTRATOR"))
hmjd
  • 120,187
  • 20
  • 207
  • 252
  • Ok thanks il change that now, I was not too sure If that worked correctly but was trying to get the function first. Thanks..:) – Natalie Carr Aug 28 '12 at 09:32
2

Your GetProductName() function takes an argument MSIHANDLE hInstall. You'll need to provide that when calling it. For instance, if you just want to call it with the same handle as RegProductName() was called with:

GetProductName(hInstall);
sonicwave
  • 5,952
  • 2
  • 33
  • 49
2

Your GetProductName looks like this:

extern "C" UINT __stdcall GetProductName(MSIHANDLE hInstall)
                                         \________________/
                                            The Argument

So it needs to take 1 argument, while you are calling it without argumanes at all:

getProductName( );
               ^
               |
            nothing is being passed here

hence the error you're getting. Based on your code you should probably pass your hInstall there:

getProductName( hInstall );
SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105
1

The GetProductName requires one argument of type MSIHANDLE whereas you are calling it without any parameter. Try instead

GetProductName(hInstall);
Patrice Bernassola
  • 14,136
  • 6
  • 46
  • 59
0

GetProductName is defined as GetProductName(MSIHANDLE hInstall), that means you MUST pass relevant MSIHANDLE as parameter. And that's exactly the error you're getting. But you're doing szProductName == "ORCHESTRATOR" - this is not how you compare strings in C. You seem to lack basic knowledge about C. You should not be writing in C or C++.

Agent_L
  • 4,960
  • 28
  • 30
  • 1
    Thanks, I don't no much about C or C++ but i am trying to learn as I go, have a few useful books and was in a rush when i wrote that. Did not think it would work but put it in quickly to post my code. Thanks – Natalie Carr Aug 28 '12 at 09:39
  • @NC1 jumping head on into complicated framework in foreign language is usually traumatic experience... – Agent_L Aug 28 '12 at 09:44