InstallSite Forum


  Reply to this topicStart new topicStart Poll

> C++ CA: The memory could not be written, Error message occurs on Custom Action
zoltan
Posted: 2010-04-09 09:04
Quote Post





Group: Full Members
Posts: 1
Member No.: 15869
Joined: 2010-04-09



Hi all,
I have a annoying problem with a custom action that validates the license key on Windows 7 (x64). The CA is implemented as C++ DLL created with the Windows Installer XML Toolkit (WiX) API. From the functional part everything works fine. The license key will be validated and the value for the license valid property (ok or not) are set properly. After I get the message "The instruction at ... referenced memory at ... The memory could not be written. Click OK to terminate the program." I can continue (license key ok) or retry enter (invalid license key).
So it seems that the DLL gets in trouble on exit and cleanup. The executing user should have administrative rights on the machine.
It seems its a common problem with CA's but I can't get a real solution. I've read that DEP could be the reason but it will not accept the setup.exe in the exclusion list. Additionally it works without an error (message) on Windows XP (32bit) and (strange but true) on my developer workstation (also Win7 x64).

Thanks in advance for every hint.
Zoltán

Here is the critical part of my CA code:
UINT __stdcall ValidateLicenseKey(MSIHANDLE hInstall)
{
char PIDKEY[256];
DWORD PIDKEYSize = sizeof(PIDKEY);
HRESULT hr = S_OK;
bool isValid=false;
char licStatus[256];
UINT er = ERROR_SUCCESS;
string lic;
hr = WcaInitialize(hInstall, "ValidateLicenseKey");
ExitOnFailure(hr, "Failed to initialize");

WcaLog(LOGMSG_STANDARD, "Initialized.");

MsiGetPropertyA(hInstall, "PID_KEY", PIDKEY, &PIDKEYSize);

if (er != ERROR_SUCCESS)
{
::MessageBoxA(NULL, "MsiGetProperty(PID_KEY) failed.", "Error", MB_OK);
return WcaFinalize(er);
}
lic = PIDKEY;
MsiSetPropertyA(hInstall, "ValidationStatus", PIDKEY);

LicenseValidation(lic,isValid,licStatus);

if (!isValid)
{
MsiSetPropertyA(hInstall, "LicenseKeyValid", "0");
}
else
{
MsiSetPropertyA(hInstall, "LicenseKeyValid", "1");
}

LExit:
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;

return WcaFinalize(er);
}


// DllMain - Initialize and cleanup WiX custom action utils.
extern "C" BOOL WINAPI DllMain(
__in HINSTANCE hInst,
__in ULONG ulReason,
__in LPVOID
)
{
switch(ulReason)
{
case DLL_PROCESS_ATTACH:
WcaGlobalInitialize(hInst);
break;

case DLL_PROCESS_DETACH:
WcaGlobalFinalize();
break;
}

return TRUE;
}
PMEmail Poster
Top

InstallShield & AdminStudio Training

Kurse in deutscher Sprache hier.

Courses in English, French and Italian language here.


« Next Oldest | Runtime Errors | Next Newest »

Topic Options Reply to this topicStart new topicStart Poll