Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Can't get property from C++ DLL function


5 replies to this topic

wolfUkr

wolfUkr
  • Members
  • 24 posts

Posted 24 May 2004 - 17:03

Hello!
Help me, please. I can't get MSI property in my function.
1. I write function GetMyProperty( MSIHANDLE hMSI) in something.dll
UINT __stdcall GetMyProperty( MSIHANDLE hMSI)throw()
{
LONG lResult;
char* lpInstallDir = new char[MAX_PATH];
DWORD pchBuff = MAX_PATH;
lResult = MsiGetProperty(hMSI, "INSTALLDIR", lpInstallDir, &pchBuff);
// property is NULL, why?
if (lResult==ERROR_SUCCESS)
MessageBox(NULL,lpInstallDir,"InstallDir Prop",NULL);
}

this function I add as custom action caGetMyProperty, who I use in installation execute sequences before OnMoved action.

caGetMyProperty - I add as MSI Dll, installed with this packege in "deferred execution"

When I try get property I get NULL string? help me get real property from my c++ code.



Glytzhkof

Glytzhkof
  • Moderators
  • 1,447 posts

Posted 24 May 2004 - 17:15

Maybe you can try this:

UINT __stdcall Function(MSIHANDLE hMSI)
{
LPCTSTR PropertyName = TEXT("INSTALLDIR");
TCHAR* szPropertyBuf;
DWORD ncharCount = 0;
UINT IResult;

// Get correct size of the buffer needed to hold the property value
IResult = MsiGetProperty(hMSI, PropertyName, TEXT(""), &ncharCount);

// Allocate memory for the property value return buffer
szPropertyBuf = (LPTSTR) malloc(++ncharCount);
IResult = MsiGetProperty(hMSI, PropertyName, szPropertyBuf, &ncharCount);

etc....

}
Regards
-Stein Åsmul

wolfUkr

wolfUkr
  • Members
  • 24 posts

Posted 24 May 2004 - 17:30

I change code without effect.
I think this problem bind with declaration custom action and use this CA in execute sequence. But where correct this problem I don't know.

When I extend my code use MsiProcessMessage, MSI window receive any data from my code. Therefore (I purpose) I use correct MSI handle.

When I change INSTALLDIR on different property or use MsiGetTargetPath situation don't change.


Glytzhkof

Glytzhkof
  • Moderators
  • 1,447 posts

Posted 24 May 2004 - 17:56

You are probably trying to access properties from a deferred execution custom action? To accomplish this you need to explicitly write the property into the execution script since the custom action cannot access the MSI database when it is deferred. To do this you use a set property custom action with the same name as the custom action that needs to access the property. How to do this has been described on this forum several times, a search should get you what you need.

If you are indeed using a deferred action, I would temporarily change it to immediate and see if this makes the property be read properly.
Regards
-Stein Åsmul

wolfUkr

wolfUkr
  • Members
  • 24 posts

Posted 24 May 2004 - 18:49

When I try use my CA without "deferred execution" (with immediate, etc. ) I get error (like "error MSI. can't run DLL who need for finish").

I add "Set property" before call my CA it's "caSetProperty", with
property name "caGetMyProperty" (like my CA), and property value "!!!" (anyone)

but this problem don't disappear



Glytzhkof

Glytzhkof
  • Moderators
  • 1,447 posts

Posted 25 May 2004 - 04:39

You probably get this message because the DLL you are trying to call is not installed yet. To work around this, you can temporarily move the custom action after InstallFinalize. Keep it in immediate mode and do a test build to see if you get the correct value back.

It is not conceptually correct to keep an immediate mode custom action after installfinalize, but this is just for testing purposes. If you get the value you expect back at least you know the DLL is OK.
Regards
-Stein Åsmul