This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Invalid handle passed from msi - (always)pls help
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jul 10, 2008
06:35 AM
Invalid handle passed from msi - (always)pls help
Hi,
I have written a sample dll and the code is given below,. It is a win32 dll.
void WINAPI Display(MSIHANDLE hInstall)
{
int i;
TCHAR* szValueBuf = NULL;
DWORD cchValueBuf = 0;
MessageBox(NULL,"creating dll","Success",MB_OK);
TCHAR *szPackagePath="D:\\LM7.0.msi";
i = MsiGetProperty(hInstall, TEXT("INSTALLDIR"),szValueBuf,&cchValueBuf);
if (i==ERROR_SUCCESS)
{
}
else
{
switch (i)
{
case ERROR_INVALID_HANDLE:
MessageBox(NULL,"Invalid handle","failure",MB_OK);
break;
case ERROR_INVALID_PARAMETER MessageBox(NULL,"Invalid parameter","failure",MB_OK);
break;
case ERROR_MORE_DATA:
MessageBox(NULL,"MORE_DATA","failure",MB_OK);
break;
default:
break;
}
}
MSIHANDLE *hProduct=NULL;
i=MsiOpenPackage(szPackagePath,hProduct);
if (i==ERROR_SUCCESS)
{
}
else
{
switch (i)
{
case ERROR_BAD_CONFIGURATION:
MessageBox(NULL,"ERROR_BAD_CONFIGURATION","failure",MB_OK);
break;
case ERROR_INSTALL_FAILURE:
MessageBox(NULL,"ERROR_INSTALL_FAILURE","failure",MB_OK);
break;
case ERROR_INVALID_PARAMETER:
MessageBox(NULL,"ERROR_INVALID_PARAMETER","failure",MB_OK);
break;
default:
break;
}
}
}
When I debug the code after the messagebox appears, I see that the MsiGetProperty returns ERROR_INVALID_HANDLE.
Now when I try to get the handle using MsiOpenPackage, then it returns ERROR_INVALID_PARAMETER, but I can see during run time that all the parameters are proper.
The Installscript code is shown below
MessageBox("Indise myfunction",WARNING);
szDll = INSTALLDIR^"test.dll";
MessageBox(szDll,WARNING);
if (0==UseDLL(szDll)) then
MessageBox("loaded test.dll",WARNING);
g_nRet = test.Display(hMSI);
Sprintf(g_szMsg,"DoInstall returned %d",g_nRet);
else
MessageBox("Unable to load dll",WARNING);
g_nRet = -1;
endif;
P.S: This invalid handle comes only when using IS2008, with IS2.01, the same code works fine.
Could anyone please let me know what may the cause, I'm banging my head with this for the past two days.
Thanks.
I have written a sample dll and the code is given below,. It is a win32 dll.
void WINAPI Display(MSIHANDLE hInstall)
{
int i;
TCHAR* szValueBuf = NULL;
DWORD cchValueBuf = 0;
MessageBox(NULL,"creating dll","Success",MB_OK);
TCHAR *szPackagePath="D:\\LM7.0.msi";
i = MsiGetProperty(hInstall, TEXT("INSTALLDIR"),szValueBuf,&cchValueBuf);
if (i==ERROR_SUCCESS)
{
}
else
{
switch (i)
{
case ERROR_INVALID_HANDLE:
MessageBox(NULL,"Invalid handle","failure",MB_OK);
break;
case ERROR_INVALID_PARAMETER MessageBox(NULL,"Invalid parameter","failure",MB_OK);
break;
case ERROR_MORE_DATA:
MessageBox(NULL,"MORE_DATA","failure",MB_OK);
break;
default:
break;
}
}
MSIHANDLE *hProduct=NULL;
i=MsiOpenPackage(szPackagePath,hProduct);
if (i==ERROR_SUCCESS)
{
}
else
{
switch (i)
{
case ERROR_BAD_CONFIGURATION:
MessageBox(NULL,"ERROR_BAD_CONFIGURATION","failure",MB_OK);
break;
case ERROR_INSTALL_FAILURE:
MessageBox(NULL,"ERROR_INSTALL_FAILURE","failure",MB_OK);
break;
case ERROR_INVALID_PARAMETER:
MessageBox(NULL,"ERROR_INVALID_PARAMETER","failure",MB_OK);
break;
default:
break;
}
}
}
When I debug the code after the messagebox appears, I see that the MsiGetProperty returns ERROR_INVALID_HANDLE.
Now when I try to get the handle using MsiOpenPackage, then it returns ERROR_INVALID_PARAMETER, but I can see during run time that all the parameters are proper.
The Installscript code is shown below
MessageBox("Indise myfunction",WARNING);
szDll = INSTALLDIR^"test.dll";
MessageBox(szDll,WARNING);
if (0==UseDLL(szDll)) then
MessageBox("loaded test.dll",WARNING);
g_nRet = test.Display(hMSI);
Sprintf(g_szMsg,"DoInstall returned %d",g_nRet);
else
MessageBox("Unable to load dll",WARNING);
g_nRet = -1;
endif;
P.S: This invalid handle comes only when using IS2008, with IS2.01, the same code works fine.
Could anyone please let me know what may the cause, I'm banging my head with this for the past two days.
Thanks.
(3) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jul 10, 2008
11:16 AM
Loading and calling this DLL from an InstallScript custom action, and then passing the hMSI parameter from your script action to the DLL, will result in an invalid handle error from any MSI functions that take an install handle. The reason this happens is because the handle is maintained by the InstallScript engine and is not usable outside of the InstallScript defined MSI functions (these functions are basically wrapper functions around the real MSI functions; the handle is translated from the InstallScript maintained handle into the real install handle).
You could use an MSI DLL custom action if you wanted to use C/C++ code directly. Windows Installer will then call your DLL passing the install handle. Note that the DLL functions need to return a value to Windows Installer indicating success or error.
You could use an MSI DLL custom action if you wanted to use C/C++ code directly. Windows Installer will then call your DLL passing the install handle. Note that the DLL functions need to return a value to Windows Installer indicating success or error.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jul 11, 2008
12:00 AM
Thanks a lot for your reply. It was really helpful to me.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jul 11, 2008
06:35 AM
I had passed the ISMSI_HANDLE inside the call to the dll function and it works properly.
![](/skins/images/CC38E504FC9E1309DC48ACFEB4925670/responsive_peak/images/icon_anonymous_message.png)