You do not use privMsiGetPropertyStr to initialize cchIniName. You initialize cchIniName like this:
char *cchIniName = new char[szBuf]; which just allocates a buffer. The contents of that buffer are undefined. > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:wix-users- > [EMAIL PROTECTED] On Behalf Of Julie Campbell > Sent: Tuesday, April 24, 2007 4:28 PM > To: 'Mike Dimmick'; wix-users@lists.sourceforge.net > Subject: Re: [WiX-users] Custom Action works under WinXP-SP2, fails > under Win2K? > > No, cchIniName is initialized, I was just saving everyone an extra > chunk of > code that is working. Here is the function that initializes cchIniName > and > the other WiX property strings before the call to fopen_s: > > // NOTE: Caller responsible for freeing TCHAR * buffer if non-null > return > code > TCHAR * __stdcall privMsiGetPropertyStr(MSIHANDLE hInstaller, TCHAR > *strName) > { > TCHAR* szValueBuf = NULL; > DWORD cchValueBuf = 0; > UINT uiStat = ::MsiGetProperty(hInstaller, strName, TEXT(""), > &cchValueBuf); > if (ERROR_MORE_DATA == uiStat) > { > ++cchValueBuf; // output count does not include terminating null, so > add 1 > szValueBuf = new TCHAR[cchValueBuf]; > if (szValueBuf) > { > uiStat = MsiGetProperty(hInstaller, strName, szValueBuf, > &cchValueBuf); > > } > } > if (ERROR_SUCCESS != uiStat) > { > if (szValueBuf != NULL) > delete [] szValueBuf; > return NULL; > } > > return szValueBuf; > } > --- > > I copied that chunk of code from somewhere, excuse the poor use of > Hungarian > notation. > > If you look at what I am writing to this ".ini" file, you will notice > that > it has nothing to do with what a <IniFile> deal with. This is a .ini > file > that supplies java startup variable to Eclipse (actually, our > customized > version of Eclipse). Eclipse is very touchy and I am afraid to try a > unicode file since it works with a text file. Heck, I wouldn't need > this CA > at all if Eclipse could figure out %WINDIR% in a path, but it can't. > > As I mentioned, this works GREAT under XP. Though this CA was quickly > hacked together and leaves room for improvement, there is nothing > intrinsically wrong with the CA code. It does what it is supposed to > as > long as the directory it is trying to write to exists before it tries > to > write the file to it. There is something wrong with the .msi > sequencing > that is baffling me, as that directory should exist long before it > tries to > execute my custom action. > > Julie Campbell > [EMAIL PROTECTED] > > > -----Original Message----- > From: Mike Dimmick [mailto:[EMAIL PROTECTED] > Sent: Tuesday, April 24, 2007 4:17 PM > To: 'Julie Campbell'; wix-users@lists.sourceforge.net > Subject: RE: [WiX-users] Custom Action works under WinXP-SP2,fails > under > Win2K? > > Your call to fopen_s uses the uninitialised cchIniName buffer as the > path > name to open for writing. > > (BTW, misuse of Hungarian notation because this is _not_ a Count of > Characters - use sz or psz for string-terminated-with-zero. If that's > what > you intended, of course.) > > You can also edit INI files using the <IniFile> element which maps to a > native Windows Installer feature. The type of the Value field is > Formatted, > so you should be able to substitute property values using [] within the > field data. > > -- > Mike Dimmick > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Julie > Campbell > Sent: 24 April 2007 21:09 > To: 'Mike Dimmick'; wix-users@lists.sourceforge.net > Subject: Re: [WiX-users] Custom Action works under WinXP-SP2,fails > under > Win2K? > > fprintf writes to the file pointed to by cchIniName. > > Julie Campbell > [EMAIL PROTECTED] > > -----Original Message----- > From: Mike Dimmick [mailto:[EMAIL PROTECTED] > Sent: Tuesday, April 24, 2007 4:05 PM > To: 'Julie Campbell'; wix-users@lists.sourceforge.net > Subject: RE: [WiX-users] Custom Action works under WinXP-SP2, fails > under > Win2K? > > Did you miss a line out? You don't appear to have written to the buffer > pointed to by cchIniName so it will be filled with garbage. The success > or > failure may depend on whether the junk in the buffer parses as a valid > file > name or not. > > I would strongly recommend using Unicode file name buffers and > therefore > _wfopen_s if you're targetting Windows NT-based operating systems only > and > not supporting Windows 9X. > > -- > Mike Dimmick > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Julie > Campbell > Sent: 24 April 2007 20:43 > To: wix-users@lists.sourceforge.net > Subject: [WiX-users] Custom Action works under WinXP-SP2, fails under > Win2K? > > My installer needs to work under WinXP and Win2K for this round. I > wrote a > custom action and it works great under WinXP but fails under Win2K and > I > cannot figure out why. I am using WiX v3.0.2420, both machines have > Windows > R Installer. V 3.01.4000.1823 installed. > > The custom action is in a C++ DLL, here is the action function: > > UINT __stdcall WriteTSBIni(MSIHANDLE hInstaller) > { > UINT rc = ERROR_SUCCESS; > > USES_CONVERSION; > > // Get the installation directory name > TCHAR *cchWindowsFolder = privMsiGetPropertyStr(hInstaller, > TEXT("WindowsFolder")); > TCHAR *cchInstallDir = privMsiGetPropertyStr(hInstaller, > TEXT("INSTALLDIR")); > TCHAR *cchIviDir = privMsiGetPropertyStr(hInstaller, > TEXT("IVIDIRPROP")); > > if (cchIviDir) > { > if (cchWindowsFolder) > { > if (cchInstallDir) > { > size_t szBuf = strlen(W2CA(cchInstallDir)) + > strlen ("Test Script Builder\\TestScriptBuilder.ini") + 1; > char *cchIniName = new char[szBuf]; > FILE *fIni; > if (errno_t err = fopen_s(&fIni, cchIniName, "w")) > { > sprintf_s(cchIniName, szBuf, "err=%d", err); > return ERROR_INSTALL_FAILURE; > } > else > { > fprintf (fIni, "-vmargs\r\n"); > fprintf (fIni, "-Djava.lang.path=.;"); > fprintf (fIni, "%s.;", W2A(cchIviDir)); > fprintf (fIni, "%s.;", W2A(cchWindowsFolder)); > fprintf (fIni, "%sSystem32\\.;\r\n", > W2A(cchWindowsFolder)); > fclose (fIni); > } > > delete[] cchIniName; > delete[] cchInstallDir; > } > > delete[] cchWindowsFolder; > } > > delete[] cchIviDir > } > > return ERROR_SUCCESS; > } > > --- > > The .wxs source snippet is: > <CustomAction Id="CAKE_WRITE_TSB_INI" BinaryKey="CAKE_ACTIONS" > DllEntry="WriteTSBIni" Return="check" /> > <InstallExecuteSequence> > <Custom Action="CAKE_WRITE_TSB_INI" After='CreateShortcuts'>NOT > Installed</Custom> > </InstallExecuteSequence> > > --- > > I ran with the /la switch and got the same sequence on both machines, > until > after the CAKE_WRITE_TSB_INI action. I checked the sequencing with > Orca, > CAKE_WRITE_TSB_INI is in the InstallExecuteSequence table at #4501, > right > after CreateShortcuts as expected. The fopen_s error that I get under > Win2K > indicates the folder doesn't exist (2). I used message boxes to pause > the > custom action and checked, and despite being past that point in the log > file > and sequence, the directory indeed was non-existent. > > I have no idea what to try next or why this is behaving differently. > Help? > > Julie Campbell > [EMAIL PROTECTED] > > > > > _______________________________________________________________________ > _____ > _ > Scanned by IBM Email Security Management Services powered by > MessageLabs. > For more information please visit http://www.ers.ibm.com > _______________________________________________________________________ > _____ > _ > > ----------------------------------------------------------------------- > -- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > WiX-users mailing list > WiX-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/wix-users > > > _______________________________________________________________________ > _____ > _ > Scanned by IBM Email Security Management Services powered by > MessageLabs. > For more information please visit http://www.ers.ibm.com > _______________________________________________________________________ > _____ > _ > > > > _______________________________________________________________________ > _____ > _ > Scanned by IBM Email Security Management Services powered by > MessageLabs. > For more information please visit http://www.ers.ibm.com > _______________________________________________________________________ > _____ > _ > > ----------------------------------------------------------------------- > -- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > WiX-users mailing list > WiX-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/wix-users > > > _______________________________________________________________________ > _____ > _ > Scanned by IBM Email Security Management Services powered by > MessageLabs. > For more information please visit http://www.ers.ibm.com > _______________________________________________________________________ > _____ > _ > > > > _______________________________________________________________________ > ______ > Scanned by IBM Email Security Management Services powered by > MessageLabs. For more information please visit http://www.ers.ibm.com > _______________________________________________________________________ > ______ > > ----------------------------------------------------------------------- > -- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > WiX-users mailing list > WiX-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/wix-users ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ WiX-users mailing list WiX-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wix-users