2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define NONAMELESSUNION
30 #include "wine/debug.h"
38 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi);
44 * The MSVC headers define the MSIDBOPEN_* macros cast to LPCTSTR,
45 * which is a problem because LPCTSTR isn't defined when compiling wine.
46 * To work around this problem, we need to define LPCTSTR as LPCWSTR here,
47 * and make sure to only use it in W functions.
49 #define LPCTSTR LPCWSTR
51 void MSI_FreePackage( MSIOBJECTHDR *arg)
53 MSIPACKAGE *package= (MSIPACKAGE*) arg;
55 ACTION_remove_tracked_tempfiles(package);
57 if (package->features && package->loaded_features > 0)
58 HeapFree(GetProcessHeap(),0,package->features);
60 if (package->folders && package->loaded_folders > 0)
61 HeapFree(GetProcessHeap(),0,package->folders);
63 if (package->components && package->loaded_components > 0)
64 HeapFree(GetProcessHeap(),0,package->components);
66 if (package->files && package->loaded_files > 0)
67 HeapFree(GetProcessHeap(),0,package->files);
68 msiobj_release( &package->db->hdr );
71 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
73 LPWSTR szwPack = NULL;
76 TRACE("%s %p\n",debugstr_a(szPackage), phPackage);
80 len = MultiByteToWideChar( CP_ACP, 0, szPackage, -1, NULL, 0 );
81 szwPack = HeapAlloc( GetProcessHeap(), 0, len * sizeof (WCHAR) );
83 MultiByteToWideChar( CP_ACP, 0, szPackage, -1, szwPack, len );
86 ret = MsiOpenPackageW( szwPack, phPackage );
89 HeapFree( GetProcessHeap(), 0, szwPack );
95 static const UINT clone_properties(MSIDATABASE *db)
97 MSIQUERY * view = NULL;
99 static const WCHAR CreateSql[] = {
100 'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','_','P','r','o',
101 'p','e','r','t','y','`',' ','(',' ','`','_','P','r','o','p','e','r','t',
102 'y','`',' ','C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U',
103 'L','L',',',' ','`','V','a','l','u','e','`',' ','C','H','A','R','(','9',
104 '8',')',' ','N','O','T',' ','N','U','L','L',' ','P','R','I','M','A','R',
105 'Y',' ','K','E','Y',' ','`','_','P','r','o','p','e','r','t','y','`',')',0};
106 static const WCHAR Query[] = {
107 'S','E','L','E','C','T',' ','*',' ',
108 'f','r','o','m',' ','P','r','o','p','e','r','t','y',0};
109 static const WCHAR Insert[] = {
110 'I','N','S','E','R','T',' ','i','n','t','o',' ',
111 '`','_','P','r','o','p','e','r','t','y','`',' ',
112 '(','`','_','P','r','o','p','e','r','t','y','`',',',
113 '`','V','a','l','u','e','`',')',' ',
114 'V','A','L','U','E','S',' ','(','?',')',0};
116 /* create the temporary properties table */
117 rc = MSI_DatabaseOpenViewW(db, CreateSql, &view);
118 if (rc != ERROR_SUCCESS)
120 rc = MSI_ViewExecute(view,0);
122 msiobj_release(&view->hdr);
123 if (rc != ERROR_SUCCESS)
126 /* clone the existing properties */
127 rc = MSI_DatabaseOpenViewW(db, Query, &view);
128 if (rc != ERROR_SUCCESS)
131 rc = MSI_ViewExecute(view, 0);
132 if (rc != ERROR_SUCCESS)
135 msiobj_release(&view->hdr);
143 rc = MSI_ViewFetch(view,&row);
144 if (rc != ERROR_SUCCESS)
147 rc = MSI_DatabaseOpenViewW(db,Insert,&view2);
148 if (rc!= ERROR_SUCCESS)
150 rc = MSI_ViewExecute(view2,row);
151 MSI_ViewClose(view2);
152 msiobj_release(&view2->hdr);
154 if (rc == ERROR_SUCCESS)
155 msiobj_release(&row->hdr);
158 msiobj_release(&view->hdr);
164 * There are a whole slew of these we need to set
167 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/properties.asp
169 static VOID set_installer_properties(MSIPACKAGE *package)
172 OSVERSIONINFOA OSVersion;
174 WCHAR verstr[10], msiver[10];
176 static const WCHAR cszbs[]={'\\',0};
177 static const WCHAR CFF[] =
178 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
179 static const WCHAR PFF[] =
180 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
181 static const WCHAR CADF[] =
182 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
183 static const WCHAR FaF[] =
184 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
185 static const WCHAR FoF[] =
186 {'F','o','n','t','s','F','o','l','d','e','r',0};
187 static const WCHAR SendTF[] =
188 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
189 static const WCHAR SMF[] =
190 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
191 static const WCHAR StF[] =
192 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
193 static const WCHAR TemplF[] =
194 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
195 static const WCHAR DF[] =
196 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
197 static const WCHAR PMF[] =
198 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
199 static const WCHAR ATF[] =
200 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
201 static const WCHAR ADF[] =
202 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
203 static const WCHAR SF[] =
204 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
205 static const WCHAR LADF[] =
206 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
207 static const WCHAR MPF[] =
208 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
209 static const WCHAR PF[] =
210 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
211 static const WCHAR WF[] =
212 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
213 static const WCHAR TF[]=
214 {'T','e','m','p','F','o','l','d','e','r',0};
215 static const WCHAR szAdminUser[] =
216 {'A','d','m','i','n','U','s','e','r',0};
217 static const WCHAR szPriv[] =
218 {'P','r','i','v','i','l','e','g','e','d',0};
219 static const WCHAR szOne[] =
221 static const WCHAR v9x[] = { 'V','e','r','s','i','o','n','9','X',0 };
222 static const WCHAR vNT[] = { 'V','e','r','s','i','o','n','N','T',0 };
223 static const WCHAR szFormat[] = {'%','l','i',0};
224 static const WCHAR szWinBuild[] =
225 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
226 static const WCHAR szSPL[] =
227 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
228 static const WCHAR szSix[] = {'6',0 };
230 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
231 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
234 * Other things I notice set
261 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES_COMMON,NULL,0,pth);
263 MSI_SetPropertyW(package, CFF, pth);
265 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES,NULL,0,pth);
267 MSI_SetPropertyW(package, PFF, pth);
269 SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL,0,pth);
271 MSI_SetPropertyW(package, CADF, pth);
273 SHGetFolderPathW(NULL,CSIDL_FAVORITES,NULL,0,pth);
275 MSI_SetPropertyW(package, FaF, pth);
277 SHGetFolderPathW(NULL,CSIDL_FONTS,NULL,0,pth);
279 MSI_SetPropertyW(package, FoF, pth);
281 SHGetFolderPathW(NULL,CSIDL_SENDTO,NULL,0,pth);
283 MSI_SetPropertyW(package, SendTF, pth);
285 SHGetFolderPathW(NULL,CSIDL_STARTMENU,NULL,0,pth);
287 MSI_SetPropertyW(package, SMF, pth);
289 SHGetFolderPathW(NULL,CSIDL_STARTUP,NULL,0,pth);
291 MSI_SetPropertyW(package, StF, pth);
293 SHGetFolderPathW(NULL,CSIDL_TEMPLATES,NULL,0,pth);
295 MSI_SetPropertyW(package, TemplF, pth);
297 SHGetFolderPathW(NULL,CSIDL_DESKTOP,NULL,0,pth);
299 MSI_SetPropertyW(package, DF, pth);
301 SHGetFolderPathW(NULL,CSIDL_PROGRAMS,NULL,0,pth);
303 MSI_SetPropertyW(package, PMF, pth);
305 SHGetFolderPathW(NULL,CSIDL_ADMINTOOLS,NULL,0,pth);
307 MSI_SetPropertyW(package, ATF, pth);
309 SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,pth);
311 MSI_SetPropertyW(package, ADF, pth);
313 SHGetFolderPathW(NULL,CSIDL_SYSTEM,NULL,0,pth);
315 MSI_SetPropertyW(package, SF, pth);
317 SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,pth);
319 MSI_SetPropertyW(package, LADF, pth);
321 SHGetFolderPathW(NULL,CSIDL_MYPICTURES,NULL,0,pth);
323 MSI_SetPropertyW(package, MPF, pth);
325 SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,0,pth);
327 MSI_SetPropertyW(package, PF, pth);
329 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
331 MSI_SetPropertyW(package, WF, pth);
333 GetTempPathW(MAX_PATH,pth);
334 MSI_SetPropertyW(package, TF, pth);
337 /* in a wine environment the user is always admin and privileged */
338 MSI_SetPropertyW(package,szAdminUser,szOne);
339 MSI_SetPropertyW(package,szPriv,szOne);
341 /* set the os things */
342 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
343 GetVersionExA(&OSVersion);
344 verval = OSVersion.dwMinorVersion+OSVersion.dwMajorVersion*100;
345 sprintfW(verstr,szFormat,verval);
346 switch (OSVersion.dwPlatformId)
348 case VER_PLATFORM_WIN32_WINDOWS:
349 MSI_SetPropertyW(package,v9x,verstr);
351 case VER_PLATFORM_WIN32_NT:
352 MSI_SetPropertyW(package,vNT,verstr);
355 sprintfW(verstr,szFormat,OSVersion.dwBuildNumber);
356 MSI_SetPropertyW(package,szWinBuild,verstr);
357 /* just fudge this */
358 MSI_SetPropertyW(package,szSPL,szSix);
360 sprintfW( msiver, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
361 MSI_SetPropertyW( package, szVersionMsi, msiver );
364 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
367 MSIDATABASE *db = NULL;
368 MSIPACKAGE *package = NULL;
370 UINT ret = ERROR_FUNCTION_FAILED;
372 static const WCHAR OriginalDatabase[] =
373 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
374 static const WCHAR Database[] =
375 {'D','A','T','A','B','A','S','E',0};
376 static const WCHAR szpi[] = {'%','i',0};
377 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
379 TRACE("%s %p\n",debugstr_w(szPackage), pPackage);
381 if (szPackage[0] == '#')
383 INT handle = atoiW(&szPackage[1]);
384 db = msihandle2msiinfo( handle , MSIHANDLETYPE_DATABASE);
388 rc = MSI_OpenDatabaseW(szPackage, MSIDBOPEN_READONLY, &db);
389 if (rc != ERROR_SUCCESS)
390 return ERROR_FUNCTION_FAILED;
393 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
398 msiobj_addref( &db->hdr );
401 package->features = NULL;
402 package->folders = NULL;
403 package->components = NULL;
404 package->files = NULL;
405 package->loaded_features = 0;
406 package->loaded_folders = 0;
407 package->loaded_components= 0;
408 package->loaded_files = 0;
410 /* OK, here is where we do a slew of things to the database to
411 * prep for all that is to come as a package */
413 clone_properties(db);
414 set_installer_properties(package);
415 MSI_SetPropertyW(package, OriginalDatabase, szPackage);
416 MSI_SetPropertyW(package, Database, szPackage);
417 sprintfW(uilevel,szpi,gUILevel);
418 MSI_SetPropertyW(package, szLevel, uilevel);
420 msiobj_addref( &package->hdr );
426 msiobj_release( &package->hdr );
428 msiobj_release( &db->hdr );
433 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
435 MSIPACKAGE *package = NULL;
438 ret = MSI_OpenPackageW( szPackage, &package);
439 if( ret == ERROR_SUCCESS )
441 *phPackage = alloc_msihandle( &package->hdr );
442 msiobj_release( &package->hdr );
447 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
449 FIXME("%s 0x%08lx %p\n",debugstr_a(szPackage), dwOptions, phPackage);
450 return ERROR_CALL_NOT_IMPLEMENTED;
453 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
455 FIXME("%s 0x%08lx %p\n",debugstr_w(szPackage), dwOptions, phPackage);
456 return ERROR_CALL_NOT_IMPLEMENTED;
459 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
462 MSIHANDLE handle = 0;
464 TRACE("(%ld)\n",hInstall);
466 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
469 handle = alloc_msihandle( &package->db->hdr );
470 msiobj_release( &package->hdr );
476 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
482 DWORD total_size = 0;
489 TRACE("%x \n",eMessageType);
492 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
493 log_type |= INSTALLLOGMODE_ERROR;
494 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
495 log_type |= INSTALLLOGMODE_WARNING;
496 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
497 log_type |= INSTALLLOGMODE_USER;
498 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
499 log_type |= INSTALLLOGMODE_INFO;
500 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
501 log_type |= INSTALLLOGMODE_COMMONDATA;
502 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
503 log_type |= INSTALLLOGMODE_ACTIONSTART;
504 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
505 log_type |= INSTALLLOGMODE_ACTIONDATA;
507 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
510 message = HeapAlloc(GetProcessHeap(),0,1*sizeof (WCHAR));
512 msg_field = MSI_RecordGetFieldCount(record);
513 for (i = 1; i <= msg_field; i++)
517 const static WCHAR format[] = { '%','i',':',' ',0};
518 const static WCHAR space[] = { ' ',0};
520 MSI_RecordGetStringW(record,i,NULL,&sz);
522 total_size+=sz*sizeof(WCHAR);
523 tmp = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
524 message = HeapReAlloc(GetProcessHeap(),0,message,total_size*sizeof (WCHAR));
526 MSI_RecordGetStringW(record,i,tmp,&sz);
530 sprintfW(number,format,i);
531 strcatW(message,number);
533 strcatW(message,tmp);
535 strcatW(message,space);
537 HeapFree(GetProcessHeap(),0,tmp);
540 TRACE("(%p %lx %lx %s)\n",gUIHandler, gUIFilter, log_type,
541 debugstr_w(message));
543 /* convert it to ASCII */
544 len = WideCharToMultiByte( CP_ACP, 0, message, -1,
545 NULL, 0, NULL, NULL );
546 msg = HeapAlloc( GetProcessHeap(), 0, len );
547 WideCharToMultiByte( CP_ACP, 0, message, -1,
548 msg, len, NULL, NULL );
550 if (gUIHandler && (gUIFilter & log_type))
552 rc = gUIHandler(gUIContext,eMessageType,msg);
555 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
556 INSTALLMESSAGE_PROGRESS))
559 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
560 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
562 if (log_file != INVALID_HANDLE_VALUE)
564 SetFilePointer(log_file,0, NULL, FILE_END);
565 WriteFile(log_file,msg,strlen(msg),&write,NULL);
566 WriteFile(log_file,"\n",1,&write,NULL);
567 CloseHandle(log_file);
570 HeapFree( GetProcessHeap(), 0, msg );
572 HeapFree(GetProcessHeap(),0,message);
573 return ERROR_SUCCESS;
576 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
579 UINT ret = ERROR_INVALID_HANDLE;
580 MSIPACKAGE *package = NULL;
581 MSIRECORD *record = NULL;
583 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
587 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
591 ret = MSI_ProcessMessage( package, eMessageType, record );
595 msiobj_release( &package->hdr );
597 msiobj_release( &record->hdr );
603 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue)
605 LPWSTR szwName = NULL, szwValue = NULL;
606 UINT hr = ERROR_INSTALL_FAILURE;
610 return ERROR_INVALID_HANDLE;
612 if (NULL == szName) {
613 return ERROR_INVALID_PARAMETER;
615 if (NULL == szValue) {
616 return ERROR_INVALID_PARAMETER;
619 len = MultiByteToWideChar( CP_ACP, 0, szName, -1, NULL, 0 );
620 szwName = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
623 MultiByteToWideChar( CP_ACP, 0, szName, -1, szwName, len );
625 len = MultiByteToWideChar( CP_ACP, 0, szValue, -1, NULL, 0 );
626 szwValue = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
629 MultiByteToWideChar( CP_ACP, 0, szValue , -1, szwValue, len );
631 hr = MsiSetPropertyW( hInstall, szwName, szwValue);
635 HeapFree( GetProcessHeap(), 0, szwName );
637 HeapFree( GetProcessHeap(), 0, szwValue );
642 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
648 static const WCHAR Insert[]=
649 {'I','N','S','E','R','T',' ','i','n','t','o',' ','`','_','P','r','o','p'
650 ,'e','r','t','y','`',' ','(','`','_','P','r','o','p','e','r','t','y','`'
651 ,',','`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
653 static const WCHAR Update[]=
654 {'U','P','D','A','T','E',' ','_','P','r','o','p','e'
655 ,'r','t','y',' ','s','e','t',' ','`','V','a','l','u','e','`',' ','='
656 ,' ','?',' ','w','h','e','r','e',' ','`','_','P','r','o','p'
657 ,'e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
660 TRACE("Setting property (%s %s)\n",debugstr_w(szName),
661 debugstr_w(szValue));
663 rc = MSI_GetPropertyW(package,szName,0,&sz);
664 if (rc==ERROR_MORE_DATA || rc == ERROR_SUCCESS)
666 sprintfW(Query,Update,szName);
668 row = MSI_CreateRecord(1);
669 MSI_RecordSetStringW(row,1,szValue);
674 strcpyW(Query,Insert);
676 row = MSI_CreateRecord(2);
677 MSI_RecordSetStringW(row,1,szName);
678 MSI_RecordSetStringW(row,2,szValue);
682 rc = MSI_DatabaseOpenViewW(package->db,Query,&view);
683 if (rc!= ERROR_SUCCESS)
685 msiobj_release(&row->hdr);
689 rc = MSI_ViewExecute(view,row);
691 msiobj_release(&row->hdr);
693 msiobj_release(&view->hdr);
698 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
703 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
705 return ERROR_INVALID_HANDLE;
706 ret = MSI_SetPropertyW( package, szName, szValue);
707 msiobj_release( &package->hdr );
711 UINT WINAPI MsiGetPropertyA(MSIHANDLE hInstall, LPCSTR szName, LPSTR szValueBuf, DWORD* pchValueBuf)
713 LPWSTR szwName = NULL, szwValueBuf = NULL;
714 UINT hr = ERROR_INSTALL_FAILURE;
717 return ERROR_INVALID_HANDLE;
719 if (NULL == szName) {
720 return ERROR_INVALID_PARAMETER;
723 TRACE("%lu %s %lu\n", hInstall, debugstr_a(szName), *pchValueBuf);
725 if (NULL != szValueBuf && NULL == pchValueBuf) {
726 return ERROR_INVALID_PARAMETER;
730 UINT len = MultiByteToWideChar( CP_ACP, 0, szName, -1, NULL, 0 );
731 szwName = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
734 MultiByteToWideChar( CP_ACP, 0, szName, -1, szwName, len );
736 return ERROR_INVALID_PARAMETER;
740 szwValueBuf = HeapAlloc( GetProcessHeap(), 0, (*pchValueBuf) * sizeof(WCHAR) );
745 if( *pchValueBuf > 0 )
747 /* be sure to blank the string first */
751 hr = MsiGetPropertyW( hInstall, szwName, szwValueBuf, pchValueBuf );
753 if( *pchValueBuf > 0 )
755 WideCharToMultiByte(CP_ACP, 0, szwValueBuf, -1, szValueBuf, *pchValueBuf, NULL, NULL);
760 HeapFree( GetProcessHeap(), 0, szwName );
762 HeapFree( GetProcessHeap(), 0, szwValueBuf );
767 UINT MSI_GetPropertyW(MSIPACKAGE *package, LPCWSTR szName,
768 LPWSTR szValueBuf, DWORD* pchValueBuf)
774 {'s','e','l','e','c','t',' ','V','a','l','u','e',' ','f','r','o','m',' '
775 ,'_','P','r','o','p','e','r','t','y',' ','w','h','e','r','e',' '
776 ,'_','P','r','o','p','e','r','t','y','=','`',0};
778 static const WCHAR szEnd[]={'`',0};
780 if (NULL == szName) {
781 return ERROR_INVALID_PARAMETER;
784 strcatW(Query,szName);
785 strcatW(Query,szEnd);
787 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
788 if (rc == ERROR_SUCCESS)
793 /* even on unsuccessful lookup native msi blanks this string */
794 if (*pchValueBuf > 0)
797 rc = MSI_ViewExecute(view, 0);
798 if (rc != ERROR_SUCCESS)
801 msiobj_release(&view->hdr);
805 rc = MSI_ViewFetch(view,&row);
806 if (rc == ERROR_SUCCESS)
809 rc = MSI_RecordGetStringW(row,1,value,&sz);
810 strncpyW(szValueBuf,value,min(sz+1,*pchValueBuf));
812 msiobj_release(&row->hdr);
815 msiobj_release(&view->hdr);
818 if (rc == ERROR_SUCCESS)
819 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
824 TRACE("property not found\n");
831 UINT WINAPI MsiGetPropertyW(MSIHANDLE hInstall, LPCWSTR szName,
832 LPWSTR szValueBuf, DWORD* pchValueBuf)
837 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
839 return ERROR_INVALID_HANDLE;
840 ret = MSI_GetPropertyW(package, szName, szValueBuf, pchValueBuf );
841 msiobj_release( &package->hdr );