Use the SourceList functions to get the source path in
[wine/hacks.git] / dlls / msi / msi.c
blob71087cd6a54c4f2b7d2825763eacc2511b4803e7
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002,2003,2004,2005 Mike McCormack 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 #include <stdarg.h>
23 #define COBJMACROS
24 #define NONAMELESSUNION
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winnls.h"
30 #include "shlwapi.h"
31 #include "wine/debug.h"
32 #include "msi.h"
33 #include "msiquery.h"
34 #include "msipriv.h"
35 #include "wincrypt.h"
36 #include "winver.h"
37 #include "winuser.h"
38 #include "wine/unicode.h"
39 #include "action.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 /* the UI level */
52 INSTALLUILEVEL gUILevel = INSTALLUILEVEL_BASIC;
53 HWND gUIhwnd = 0;
54 INSTALLUI_HANDLERA gUIHandlerA = NULL;
55 INSTALLUI_HANDLERW gUIHandlerW = NULL;
56 DWORD gUIFilter = 0;
57 LPVOID gUIContext = NULL;
58 WCHAR gszLogFile[MAX_PATH];
59 HINSTANCE msi_hInstance;
61 static const WCHAR installerW[] = {'\\','I','n','s','t','a','l','l','e','r',0};
63 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
65 UINT r;
66 LPWSTR szwProd = NULL;
68 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
70 if( szProduct )
72 szwProd = strdupAtoW( szProduct );
73 if( !szwProd )
74 return ERROR_OUTOFMEMORY;
77 r = MsiOpenProductW( szwProd, phProduct );
79 HeapFree( GetProcessHeap(), 0, szwProd );
81 return r;
84 UINT WINAPI MsiOpenProductW(LPCWSTR szProduct, MSIHANDLE *phProduct)
86 LPWSTR path = NULL;
87 UINT r;
88 HKEY hKeyProduct = NULL;
89 DWORD count, type;
91 TRACE("%s %p\n",debugstr_w(szProduct), phProduct);
93 r = MSIREG_OpenUninstallKey(szProduct,&hKeyProduct,FALSE);
94 if( r != ERROR_SUCCESS )
96 r = ERROR_UNKNOWN_PRODUCT;
97 goto end;
100 /* find the size of the path */
101 type = count = 0;
102 r = RegQueryValueExW( hKeyProduct, INSTALLPROPERTY_LOCALPACKAGEstringW,
103 NULL, &type, NULL, &count );
104 if( r != ERROR_SUCCESS )
106 r = ERROR_UNKNOWN_PRODUCT;
107 goto end;
110 /* now alloc and fetch the path of the database to open */
111 path = HeapAlloc( GetProcessHeap(), 0, count );
112 if( !path )
113 goto end;
115 r = RegQueryValueExW( hKeyProduct, INSTALLPROPERTY_LOCALPACKAGEstringW,
116 NULL, &type, (LPBYTE) path, &count );
117 if( r != ERROR_SUCCESS )
119 r = ERROR_UNKNOWN_PRODUCT;
120 goto end;
123 r = MsiOpenPackageW( path, phProduct );
125 end:
126 HeapFree( GetProcessHeap(), 0, path );
127 if( hKeyProduct )
128 RegCloseKey( hKeyProduct );
130 return r;
133 UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
134 LPCSTR szTransforms, LANGID lgidLanguage)
136 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath),
137 debugstr_a(szScriptfilePath), debugstr_a(szTransforms), lgidLanguage);
138 return ERROR_CALL_NOT_IMPLEMENTED;
141 UINT WINAPI MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
142 LPCWSTR szTransforms, LANGID lgidLanguage)
144 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath),
145 debugstr_w(szScriptfilePath), debugstr_w(szTransforms), lgidLanguage);
146 return ERROR_CALL_NOT_IMPLEMENTED;
149 UINT WINAPI MsiAdvertiseProductExA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
150 LPCSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
152 FIXME("%s %s %s %08x %08lx %08lx\n", debugstr_a(szPackagePath),
153 debugstr_a(szScriptfilePath), debugstr_a(szTransforms),
154 lgidLanguage, dwPlatform, dwOptions);
155 return ERROR_CALL_NOT_IMPLEMENTED;
158 UINT WINAPI MsiAdvertiseProductExW( LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
159 LPCWSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
161 FIXME("%s %s %s %08x %08lx %08lx\n", debugstr_w(szPackagePath),
162 debugstr_w(szScriptfilePath), debugstr_w(szTransforms),
163 lgidLanguage, dwPlatform, dwOptions);
164 return ERROR_CALL_NOT_IMPLEMENTED;
167 UINT WINAPI MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)
169 LPWSTR szwPath = NULL, szwCommand = NULL;
170 UINT r = ERROR_OUTOFMEMORY;
172 TRACE("%s %s\n",debugstr_a(szPackagePath), debugstr_a(szCommandLine));
174 if( szPackagePath )
176 szwPath = strdupAtoW( szPackagePath );
177 if( !szwPath )
178 goto end;
181 if( szCommandLine )
183 szwCommand = strdupAtoW( szCommandLine );
184 if( !szwCommand )
185 goto end;
188 r = MsiInstallProductW( szwPath, szwCommand );
190 end:
191 HeapFree( GetProcessHeap(), 0, szwPath );
192 HeapFree( GetProcessHeap(), 0, szwCommand );
194 return r;
197 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
199 MSIPACKAGE *package = NULL;
200 UINT r;
201 MSIHANDLE handle;
202 WCHAR path[MAX_PATH];
203 WCHAR filename[MAX_PATH];
204 static const WCHAR szMSI[] = {'M','S','I',0};
206 FIXME("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
208 r = MsiVerifyPackageW(szPackagePath);
209 if (r != ERROR_SUCCESS)
210 return r;
212 /* copy the msi file to a temp file to pervent locking a CD
213 * with a multi disc install
215 GetTempPathW(MAX_PATH, path);
216 GetTempFileNameW(path, szMSI, 0, filename);
218 CopyFileW(szPackagePath, filename, FALSE);
220 TRACE("Opening relocated package %s\n",debugstr_w(filename));
221 r = MSI_OpenPackageW(filename, &package);
222 if (r != ERROR_SUCCESS)
224 DeleteFileW(filename);
225 return r;
228 handle = alloc_msihandle( &package->hdr );
230 r = ACTION_DoTopLevelINSTALL(package, szPackagePath, szCommandLine,
231 filename);
233 MsiCloseHandle(handle);
234 msiobj_release( &package->hdr );
236 DeleteFileW(filename);
237 return r;
240 UINT WINAPI MsiReinstallProductA(LPCSTR szProduct, DWORD dwReinstallMode)
242 FIXME("%s %08lx\n", debugstr_a(szProduct), dwReinstallMode);
243 return ERROR_CALL_NOT_IMPLEMENTED;
246 UINT WINAPI MsiReinstallProductW(LPCWSTR szProduct, DWORD dwReinstallMode)
248 FIXME("%s %08lx\n", debugstr_w(szProduct), dwReinstallMode);
249 return ERROR_CALL_NOT_IMPLEMENTED;
252 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
253 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
255 FIXME("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
256 eInstallType, debugstr_a(szCommandLine));
257 return ERROR_CALL_NOT_IMPLEMENTED;
260 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
261 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
263 FIXME("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
264 eInstallType, debugstr_w(szCommandLine));
265 return ERROR_CALL_NOT_IMPLEMENTED;
268 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
269 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
271 MSIHANDLE handle = -1;
272 MSIPACKAGE* package;
273 UINT rc;
274 DWORD sz;
275 WCHAR sourcepath[MAX_PATH];
276 WCHAR filename[MAX_PATH];
277 static const WCHAR szInstalled[] = {
278 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
279 LPWSTR commandline;
281 FIXME("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
282 debugstr_w(szCommandLine));
284 if (eInstallState != INSTALLSTATE_LOCAL &&
285 eInstallState != INSTALLSTATE_DEFAULT)
287 FIXME("Not implemented for anything other than local installs\n");
288 return ERROR_CALL_NOT_IMPLEMENTED;
291 sz = sizeof(sourcepath);
292 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
293 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEstringW, sourcepath,
294 &sz);
296 sz = sizeof(filename);
297 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
298 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEstringW, filename, &sz);
300 strcatW(sourcepath,filename);
303 * ok 1, we need to find the msi file for this product.
304 * 2, find the source dir for the files
305 * 3, do the configure/install.
306 * 4, cleanupany runonce entry.
309 rc = MsiOpenProductW(szProduct,&handle);
310 if (rc != ERROR_SUCCESS)
311 goto end;
313 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
314 if (!package)
316 rc = ERROR_INVALID_HANDLE;
317 goto end;
320 sz = lstrlenW(szInstalled);
322 if (szCommandLine)
323 sz += lstrlenW(szCommandLine);
325 commandline = HeapAlloc(GetProcessHeap(),0,sz * sizeof(WCHAR));
327 if (szCommandLine)
328 lstrcpyW(commandline,szCommandLine);
329 else
330 commandline[0] = 0;
332 if (MsiQueryProductStateW(szProduct) != INSTALLSTATE_UNKNOWN)
333 lstrcatW(commandline,szInstalled);
335 rc = ACTION_DoTopLevelINSTALL(package, sourcepath, commandline, sourcepath);
337 msiobj_release( &package->hdr );
339 HeapFree(GetProcessHeap(),0,commandline);
340 end:
341 if (handle != -1)
342 MsiCloseHandle(handle);
344 return rc;
347 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
348 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
350 LPWSTR szwProduct = NULL;
351 LPWSTR szwCommandLine = NULL;
352 UINT r = ERROR_OUTOFMEMORY;
354 if( szProduct )
356 szwProduct = strdupAtoW( szProduct );
357 if( !szwProduct )
358 goto end;
361 if( szCommandLine)
363 szwCommandLine = strdupAtoW( szCommandLine );
364 if( !szwCommandLine)
365 goto end;
368 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
369 szwCommandLine );
370 end:
371 HeapFree( GetProcessHeap(), 0, szwProduct );
372 HeapFree( GetProcessHeap(), 0, szwCommandLine);
374 return r;
377 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
378 INSTALLSTATE eInstallState)
380 LPWSTR szwProduct = NULL;
381 UINT r;
383 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
385 if( szProduct )
387 szwProduct = strdupAtoW( szProduct );
388 if( !szwProduct )
389 return ERROR_OUTOFMEMORY;
392 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
393 HeapFree( GetProcessHeap(), 0, szwProduct );
395 return r;
398 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
399 INSTALLSTATE eInstallState)
401 FIXME("%s %d %d\n", debugstr_w(szProduct), iInstallLevel, eInstallState);
403 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
406 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
408 LPWSTR szwComponent = NULL;
409 UINT r;
410 WCHAR szwBuffer[GUID_SIZE];
412 TRACE("%s %s\n",debugstr_a(szComponent), debugstr_a(szBuffer));
414 if( szComponent )
416 szwComponent = strdupAtoW( szComponent );
417 if( !szwComponent )
418 return ERROR_OUTOFMEMORY;
421 r = MsiGetProductCodeW( szwComponent, szwBuffer );
423 if( ERROR_SUCCESS == r )
424 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
426 HeapFree( GetProcessHeap(), 0, szwComponent );
428 return r;
431 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
433 UINT rc;
434 HKEY hkey;
435 WCHAR szSquished[GUID_SIZE];
436 DWORD sz = GUID_SIZE;
437 static const WCHAR szPermKey[] =
438 { '0','0','0','0','0','0','0','0','0','0','0','0',
439 '0','0','0','0','0','0','0', '0','0','0','0','0',
440 '0','0','0','0','0','0','0','0',0};
442 TRACE("%s %p\n",debugstr_w(szComponent), szBuffer);
444 if (NULL == szComponent)
445 return ERROR_INVALID_PARAMETER;
447 rc = MSIREG_OpenComponentsKey( szComponent, &hkey, FALSE);
448 if (rc != ERROR_SUCCESS)
449 return ERROR_UNKNOWN_COMPONENT;
451 rc = RegEnumValueW(hkey, 0, szSquished, &sz, NULL, NULL, NULL, NULL);
452 if (rc == ERROR_SUCCESS && strcmpW(szSquished,szPermKey)==0)
454 sz = GUID_SIZE;
455 rc = RegEnumValueW(hkey, 1, szSquished, &sz, NULL, NULL, NULL, NULL);
458 RegCloseKey(hkey);
460 if (rc != ERROR_SUCCESS)
461 return ERROR_INSTALL_FAILURE;
463 unsquash_guid(szSquished, szBuffer);
464 return ERROR_SUCCESS;
467 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
468 LPSTR szBuffer, DWORD *pcchValueBuf)
470 LPWSTR szwProduct = NULL, szwAttribute = NULL, szwBuffer = NULL;
471 UINT r = ERROR_OUTOFMEMORY;
472 DWORD pcchwValueBuf = 0;
474 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
475 szBuffer, pcchValueBuf);
477 if( szProduct )
479 szwProduct = strdupAtoW( szProduct );
480 if( !szwProduct )
481 goto end;
484 if( szAttribute )
486 szwAttribute = strdupAtoW( szAttribute );
487 if( !szwAttribute )
488 goto end;
491 if( szBuffer )
493 szwBuffer = HeapAlloc( GetProcessHeap(), 0, (*pcchValueBuf) * sizeof(WCHAR) );
494 pcchwValueBuf = *pcchValueBuf;
495 if( !szwBuffer )
496 goto end;
499 r = MsiGetProductInfoW( szwProduct, szwAttribute, szwBuffer,
500 &pcchwValueBuf );
502 if( ERROR_SUCCESS == r )
503 *pcchValueBuf = WideCharToMultiByte(CP_ACP, 0, szwBuffer, pcchwValueBuf,
504 szBuffer, *pcchValueBuf, NULL, NULL);
506 end:
507 HeapFree( GetProcessHeap(), 0, szwProduct );
508 HeapFree( GetProcessHeap(), 0, szwAttribute );
509 HeapFree( GetProcessHeap(), 0, szwBuffer );
511 return r;
514 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
515 LPWSTR szBuffer, DWORD *pcchValueBuf)
517 MSIHANDLE hProduct;
518 UINT r;
519 static const WCHAR szProductVersion[] =
520 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
521 static const WCHAR szProductLanguage[] =
522 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
524 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szAttribute),
525 szBuffer, pcchValueBuf);
527 if (NULL != szBuffer && NULL == pcchValueBuf)
528 return ERROR_INVALID_PARAMETER;
529 if (NULL == szProduct || NULL == szAttribute)
530 return ERROR_INVALID_PARAMETER;
532 /* check for special properties */
533 if (strcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEstringW)==0)
535 HKEY hkey;
536 WCHAR squished[GUID_SIZE];
537 WCHAR package[200];
538 DWORD sz = sizeof(squished);
540 r = MSIREG_OpenUserProductsKey(szProduct, &hkey, FALSE);
541 if (r != ERROR_SUCCESS)
542 return ERROR_UNKNOWN_PRODUCT;
544 r = RegQueryValueExW(hkey, INSTALLPROPERTY_PACKAGECODEstringW, NULL, NULL,
545 (LPBYTE)squished, &sz);
546 if (r != ERROR_SUCCESS)
548 RegCloseKey(hkey);
549 return ERROR_UNKNOWN_PRODUCT;
552 unsquash_guid(squished, package);
553 *pcchValueBuf = strlenW(package);
554 if (strlenW(package) > *pcchValueBuf)
556 RegCloseKey(hkey);
557 return ERROR_MORE_DATA;
559 else
560 strcpyW(szBuffer, package);
562 RegCloseKey(hkey);
563 r = ERROR_SUCCESS;
565 else if (strcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGstringW)==0)
567 r = MsiOpenProductW(szProduct, &hProduct);
568 if (ERROR_SUCCESS != r)
569 return r;
571 r = MsiGetPropertyW(hProduct, szProductVersion, szBuffer, pcchValueBuf);
572 MsiCloseHandle(hProduct);
574 else if (strcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEstringW)==0)
576 FIXME("0 (zero) if advertised or per user , 1(one) if per machine.\n");
577 if (szBuffer)
579 szBuffer[0] = '1';
580 szBuffer[1] = 0;
582 if (pcchValueBuf)
583 *pcchValueBuf = 1;
584 r = ERROR_SUCCESS;
586 else if (strcmpW(szAttribute, INSTALLPROPERTY_LANGUAGEstringW)==0)
588 r = MsiOpenProductW(szProduct, &hProduct);
589 if (ERROR_SUCCESS != r)
590 return r;
592 r = MsiGetPropertyW(hProduct, szProductLanguage, szBuffer, pcchValueBuf);
593 MsiCloseHandle(hProduct);
595 else
597 r = MsiOpenProductW(szProduct, &hProduct);
598 if (ERROR_SUCCESS != r)
599 return r;
601 r = MsiGetPropertyW(hProduct, szAttribute, szBuffer, pcchValueBuf);
602 MsiCloseHandle(hProduct);
605 return r;
608 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
610 LPWSTR szwLogFile = NULL;
611 UINT r;
613 TRACE("%08lx %s %08lx\n", dwLogMode, debugstr_a(szLogFile), attributes);
615 if( szLogFile )
617 szwLogFile = strdupAtoW( szLogFile );
618 if( !szwLogFile )
619 return ERROR_OUTOFMEMORY;
621 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
622 HeapFree( GetProcessHeap(), 0, szwLogFile );
623 return r;
626 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
628 HANDLE file = INVALID_HANDLE_VALUE;
630 TRACE("%08lx %s %08lx\n", dwLogMode, debugstr_w(szLogFile), attributes);
632 lstrcpyW(gszLogFile,szLogFile);
633 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
634 DeleteFileW(szLogFile);
635 file = CreateFileW(szLogFile, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
636 FILE_ATTRIBUTE_NORMAL, NULL);
637 if (file != INVALID_HANDLE_VALUE)
638 CloseHandle(file);
639 else
640 ERR("Unable to enable log %s\n",debugstr_w(szLogFile));
642 return ERROR_SUCCESS;
645 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
647 LPWSTR szwProduct = NULL;
648 INSTALLSTATE r;
650 if( szProduct )
652 szwProduct = strdupAtoW( szProduct );
653 if( !szwProduct )
654 return ERROR_OUTOFMEMORY;
656 r = MsiQueryProductStateW( szwProduct );
657 HeapFree( GetProcessHeap(), 0, szwProduct );
658 return r;
661 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
663 UINT rc;
664 INSTALLSTATE rrc = INSTALLSTATE_UNKNOWN;
665 HKEY hkey = 0;
666 static const WCHAR szWindowsInstaller[] = {
667 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0 };
668 DWORD sz;
670 TRACE("%s\n", debugstr_w(szProduct));
672 rc = MSIREG_OpenUserProductsKey(szProduct,&hkey,FALSE);
673 if (rc != ERROR_SUCCESS)
674 goto end;
676 RegCloseKey(hkey);
678 rc = MSIREG_OpenUninstallKey(szProduct,&hkey,FALSE);
679 if (rc != ERROR_SUCCESS)
680 goto end;
682 sz = sizeof(rrc);
683 rc = RegQueryValueExW(hkey,szWindowsInstaller,NULL,NULL,(LPVOID)&rrc, &sz);
684 if (rc != ERROR_SUCCESS)
685 goto end;
687 switch (rrc)
689 case 1:
690 /* default */
691 rrc = INSTALLSTATE_DEFAULT;
692 break;
693 default:
694 FIXME("Unknown install state read from registry (%i)\n",rrc);
695 rrc = INSTALLSTATE_UNKNOWN;
696 break;
698 end:
699 RegCloseKey(hkey);
700 return rrc;
703 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
705 INSTALLUILEVEL old = gUILevel;
706 HWND oldwnd = gUIhwnd;
708 TRACE("%08x %p\n", dwUILevel, phWnd);
710 gUILevel = dwUILevel;
711 if (phWnd)
713 gUIhwnd = *phWnd;
714 *phWnd = oldwnd;
716 return old;
719 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
720 DWORD dwMessageFilter, LPVOID pvContext)
722 INSTALLUI_HANDLERA prev = gUIHandlerA;
724 TRACE("%p %lx %p\n",puiHandler, dwMessageFilter,pvContext);
725 gUIHandlerA = puiHandler;
726 gUIFilter = dwMessageFilter;
727 gUIContext = pvContext;
729 return prev;
732 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
733 DWORD dwMessageFilter, LPVOID pvContext)
735 INSTALLUI_HANDLERW prev = gUIHandlerW;
737 TRACE("%p %lx %p\n",puiHandler,dwMessageFilter,pvContext);
738 gUIHandlerW = puiHandler;
739 gUIFilter = dwMessageFilter;
740 gUIContext = pvContext;
742 return prev;
745 /******************************************************************
746 * MsiLoadStringW [MSI.@]
748 * Loads a string from MSI's string resources.
750 * PARAMS
752 * handle [I] only -1 is handled currently
753 * id [I] id of the string to be loaded
754 * lpBuffer [O] buffer for the string to be written to
755 * nBufferMax [I] maximum size of the buffer in characters
756 * lang [I] the preferred language for the string
758 * RETURNS
760 * If successful, this function returns the language id of the string loaded
761 * If the function fails, the function returns zero.
763 * NOTES
765 * The type of the first parameter is unknown. LoadString's prototype
766 * suggests that it might be a module handle. I have made it an MSI handle
767 * for starters, as -1 is an invalid MSI handle, but not an invalid module
768 * handle. Maybe strings can be stored in an MSI database somehow.
770 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
771 int nBufferMax, LANGID lang )
773 HRSRC hres;
774 HGLOBAL hResData;
775 LPWSTR p;
776 DWORD i, len;
778 TRACE("%ld %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
780 if( handle != -1 )
781 FIXME("don't know how to deal with handle = %08lx\n", handle);
783 if( !lang )
784 lang = GetUserDefaultLangID();
786 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
787 (LPWSTR)1, lang );
788 if( !hres )
789 return 0;
790 hResData = LoadResource( msi_hInstance, hres );
791 if( !hResData )
792 return 0;
793 p = LockResource( hResData );
794 if( !p )
795 return 0;
797 for (i = 0; i < (id&0xf); i++)
798 p += *p + 1;
799 len = *p;
801 if( nBufferMax <= len )
802 return 0;
804 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
805 lpBuffer[ len ] = 0;
807 TRACE("found -> %s\n", debugstr_w(lpBuffer));
809 return lang;
812 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
813 int nBufferMax, LANGID lang )
815 LPWSTR bufW;
816 LANGID r;
817 DWORD len;
819 bufW = HeapAlloc(GetProcessHeap(), 0, nBufferMax*sizeof(WCHAR));
820 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
821 if( r )
823 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
824 if( len <= nBufferMax )
825 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
826 lpBuffer, nBufferMax, NULL, NULL );
827 else
828 r = 0;
830 HeapFree(GetProcessHeap(), 0, bufW);
831 return r;
834 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
835 DWORD *pcchBuf)
837 FIXME("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
838 return INSTALLSTATE_UNKNOWN;
841 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
842 DWORD *pcchBuf)
844 FIXME("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
845 return INSTALLSTATE_UNKNOWN;
848 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
849 WORD wLanguageId, DWORD f)
851 FIXME("%p %s %s %u %08x %08lx\n",hWnd,debugstr_a(lpText),debugstr_a(lpCaption),
852 uType,wLanguageId,f);
853 return ERROR_CALL_NOT_IMPLEMENTED;
856 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
857 WORD wLanguageId, DWORD f)
859 FIXME("%p %s %s %u %08x %08lx\n",hWnd,debugstr_w(lpText),debugstr_w(lpCaption),
860 uType,wLanguageId,f);
861 return ERROR_CALL_NOT_IMPLEMENTED;
864 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
865 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
866 DWORD* pcchPathBuf )
868 FIXME("%s %s %08lx %08lx %p %p\n", debugstr_a(szAssemblyName),
869 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
870 pcchPathBuf);
871 return ERROR_CALL_NOT_IMPLEMENTED;
874 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
875 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
876 DWORD* pcchPathBuf )
878 FIXME("%s %s %08lx %08lx %p %p\n", debugstr_w(szAssemblyName),
879 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
880 pcchPathBuf);
881 return ERROR_CALL_NOT_IMPLEMENTED;
884 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
885 LPSTR szPath, DWORD *pcchPath, DWORD *pcchArgs )
887 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
888 return ERROR_CALL_NOT_IMPLEMENTED;
891 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
892 LPWSTR szPath, DWORD *pcchPath, DWORD *pcchArgs )
894 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
895 return ERROR_CALL_NOT_IMPLEMENTED;
898 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath,
899 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, BYTE* pbHashData,
900 DWORD* pcbHashData)
902 FIXME("%s %08lx %p %p %p\n", debugstr_a(szSignedObjectPath), dwFlags,
903 ppcCertContext, pbHashData, pcbHashData);
904 return ERROR_CALL_NOT_IMPLEMENTED;
907 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath,
908 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, BYTE* pbHashData,
909 DWORD* pcbHashData)
911 FIXME("%s %08lx %p %p %p\n", debugstr_w(szSignedObjectPath), dwFlags,
912 ppcCertContext, pbHashData, pcbHashData);
913 return ERROR_CALL_NOT_IMPLEMENTED;
916 UINT WINAPI MsiGetProductPropertyA( MSIHANDLE hProduct, LPCSTR szProperty,
917 LPSTR szValue, DWORD *pccbValue )
919 FIXME("%ld %s %p %p\n", hProduct, debugstr_a(szProperty), szValue, pccbValue);
920 return ERROR_CALL_NOT_IMPLEMENTED;
923 UINT WINAPI MsiGetProductPropertyW( MSIHANDLE hProduct, LPCWSTR szProperty,
924 LPWSTR szValue, DWORD *pccbValue )
926 FIXME("%ld %s %p %p\n", hProduct, debugstr_w(szProperty), szValue, pccbValue);
927 return ERROR_CALL_NOT_IMPLEMENTED;
930 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
932 UINT r;
933 LPWSTR szPack = NULL;
935 TRACE("%s\n", debugstr_a(szPackage) );
937 if( szPackage )
939 szPack = strdupAtoW( szPackage );
940 if( !szPack )
941 return ERROR_OUTOFMEMORY;
944 r = MsiVerifyPackageW( szPack );
946 HeapFree( GetProcessHeap(), 0, szPack );
948 return r;
951 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
953 MSIHANDLE handle;
954 UINT r;
956 TRACE("%s\n", debugstr_w(szPackage) );
958 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
959 MsiCloseHandle( handle );
961 return r;
964 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
965 LPSTR lpPathBuf, DWORD* pcchBuf)
967 LPWSTR szwProduct = NULL, szwComponent = NULL, lpwPathBuf= NULL;
968 INSTALLSTATE rc;
969 UINT incoming_len;
971 if( szProduct )
973 szwProduct = strdupAtoW( szProduct );
974 if( !szwProduct)
975 return ERROR_OUTOFMEMORY;
978 if( szComponent )
980 szwComponent = strdupAtoW( szComponent );
981 if( !szwComponent )
983 HeapFree( GetProcessHeap(), 0, szwProduct);
984 return ERROR_OUTOFMEMORY;
988 if( pcchBuf && *pcchBuf > 0 )
990 lpwPathBuf = HeapAlloc( GetProcessHeap(), 0, *pcchBuf * sizeof(WCHAR));
991 incoming_len = *pcchBuf;
993 else
995 lpwPathBuf = NULL;
996 incoming_len = 0;
999 rc = MsiGetComponentPathW(szwProduct, szwComponent, lpwPathBuf, pcchBuf);
1001 HeapFree( GetProcessHeap(), 0, szwProduct);
1002 HeapFree( GetProcessHeap(), 0, szwComponent);
1003 if (lpwPathBuf)
1005 if (rc != INSTALLSTATE_UNKNOWN)
1006 WideCharToMultiByte(CP_ACP, 0, lpwPathBuf, incoming_len,
1007 lpPathBuf, incoming_len, NULL, NULL);
1008 HeapFree( GetProcessHeap(), 0, lpwPathBuf);
1011 return rc;
1014 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
1015 LPWSTR lpPathBuf, DWORD* pcchBuf)
1017 WCHAR squished_pc[GUID_SIZE];
1018 UINT rc;
1019 INSTALLSTATE rrc = INSTALLSTATE_UNKNOWN;
1020 HKEY hkey = 0;
1021 LPWSTR path = NULL;
1022 DWORD sz, type;
1024 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
1025 debugstr_w(szComponent), lpPathBuf, pcchBuf);
1027 if( lpPathBuf && !pcchBuf )
1028 return INSTALLSTATE_INVALIDARG;
1030 squash_guid(szProduct,squished_pc);
1032 rc = MSIREG_OpenProductsKey( szProduct, &hkey, FALSE);
1033 if( rc != ERROR_SUCCESS )
1034 goto end;
1036 RegCloseKey(hkey);
1038 rc = MSIREG_OpenComponentsKey( szComponent, &hkey, FALSE);
1039 if( rc != ERROR_SUCCESS )
1040 goto end;
1042 sz = 0;
1043 type = 0;
1044 rc = RegQueryValueExW( hkey, squished_pc, NULL, &type, NULL, &sz );
1045 if( rc != ERROR_SUCCESS )
1046 goto end;
1047 if( type != REG_SZ )
1048 goto end;
1050 sz += sizeof(WCHAR);
1051 path = HeapAlloc( GetProcessHeap(), 0, sz );
1052 if( !path )
1053 goto end;
1055 rc = RegQueryValueExW( hkey, squished_pc, NULL, NULL, (LPVOID) path, &sz );
1056 if( rc != ERROR_SUCCESS )
1057 goto end;
1059 TRACE("found path of (%s:%s)(%s)\n", debugstr_w(szComponent),
1060 debugstr_w(szProduct), debugstr_w(path));
1062 if (path[0]=='0')
1064 FIXME("Registry entry.. check entry\n");
1065 rrc = INSTALLSTATE_LOCAL;
1067 else
1069 /* PROBABLY a file */
1070 if ( GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES )
1071 rrc = INSTALLSTATE_LOCAL;
1072 else
1073 rrc = INSTALLSTATE_ABSENT;
1076 if( pcchBuf )
1078 sz = sz / sizeof(WCHAR);
1079 if( *pcchBuf >= sz )
1080 lstrcpyW( lpPathBuf, path );
1081 *pcchBuf = sz;
1084 end:
1085 HeapFree(GetProcessHeap(), 0, path );
1086 RegCloseKey(hkey);
1087 return rrc;
1090 /******************************************************************
1091 * MsiQueryFeatureStateA [MSI.@]
1093 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
1095 INSTALLSTATE rc;
1096 LPWSTR szwProduct= NULL;
1097 LPWSTR szwFeature= NULL;
1099 if( szProduct )
1101 szwProduct = strdupAtoW( szProduct );
1102 if( !szwProduct)
1103 return ERROR_OUTOFMEMORY;
1106 if( szFeature )
1108 szwFeature = strdupAtoW( szFeature );
1109 if( !szwFeature)
1111 HeapFree( GetProcessHeap(), 0, szwProduct);
1112 return ERROR_OUTOFMEMORY;
1116 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
1118 HeapFree( GetProcessHeap(), 0, szwProduct);
1119 HeapFree( GetProcessHeap(), 0, szwFeature);
1121 return rc;
1124 /******************************************************************
1125 * MsiQueryFeatureStateW [MSI.@]
1127 * This does not verify that the Feature is functional. So i am only going to
1128 * check the existence of the key in the registry. This should tell me if it is
1129 * installed.
1131 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
1133 UINT rc;
1134 DWORD sz = 0;
1135 HKEY hkey;
1137 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
1139 rc = MSIREG_OpenFeaturesKey(szProduct, &hkey, FALSE);
1140 if (rc != ERROR_SUCCESS)
1141 return INSTALLSTATE_UNKNOWN;
1143 rc = RegQueryValueExW( hkey, szFeature, NULL, NULL, NULL, &sz);
1144 RegCloseKey(hkey);
1146 if (rc == ERROR_SUCCESS)
1147 return INSTALLSTATE_LOCAL;
1148 else
1149 return INSTALLSTATE_ABSENT;
1152 /******************************************************************
1153 * MsiGetFileVersionA [MSI.@]
1155 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
1156 DWORD* pcchVersionBuf, LPSTR lpLangBuf, DWORD* pcchLangBuf)
1158 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
1159 UINT ret = ERROR_OUTOFMEMORY;
1161 if( szFilePath )
1163 szwFilePath = strdupAtoW( szFilePath );
1164 if( !szwFilePath )
1165 goto end;
1168 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
1170 lpwVersionBuff = HeapAlloc(GetProcessHeap(), 0, *pcchVersionBuf*sizeof(WCHAR));
1171 if( !lpwVersionBuff )
1172 goto end;
1175 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
1177 lpwLangBuff = HeapAlloc(GetProcessHeap(), 0, *pcchVersionBuf*sizeof(WCHAR));
1178 if( !lpwLangBuff )
1179 goto end;
1182 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
1183 lpwLangBuff, pcchLangBuf);
1185 if( lpwVersionBuff )
1186 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
1187 lpVersionBuf, *pcchVersionBuf, NULL, NULL);
1188 if( lpwLangBuff )
1189 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
1190 lpLangBuf, *pcchLangBuf, NULL, NULL);
1192 end:
1193 HeapFree(GetProcessHeap(), 0, szwFilePath);
1194 HeapFree(GetProcessHeap(), 0, lpwVersionBuff);
1195 HeapFree(GetProcessHeap(), 0, lpwLangBuff);
1197 return ret;
1200 /******************************************************************
1201 * MsiGetFileVersionW [MSI.@]
1203 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
1204 DWORD* pcchVersionBuf, LPWSTR lpLangBuf, DWORD* pcchLangBuf)
1206 static const WCHAR szVersionResource[] = {'\\',0};
1207 static const WCHAR szVersionFormat[] = {
1208 '%','d','.','%','d','.','%','d','.','%','d',0};
1209 static const WCHAR szLangFormat[] = {'%','d',0};
1210 UINT ret = 0;
1211 DWORD dwVerLen;
1212 LPVOID lpVer = NULL;
1213 VS_FIXEDFILEINFO *ffi;
1214 UINT puLen;
1215 WCHAR tmp[32];
1217 TRACE("%s %p %ld %p %ld\n", debugstr_w(szFilePath),
1218 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
1219 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
1221 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
1222 if( !dwVerLen )
1223 return GetLastError();
1225 lpVer = HeapAlloc(GetProcessHeap(), 0, dwVerLen);
1226 if( !lpVer )
1228 ret = ERROR_OUTOFMEMORY;
1229 goto end;
1232 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
1234 ret = GetLastError();
1235 goto end;
1237 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
1239 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
1240 (puLen > 0) )
1242 wsprintfW(tmp, szVersionFormat,
1243 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
1244 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
1245 lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
1246 *pcchVersionBuf = lstrlenW(lpVersionBuf);
1248 else
1250 *lpVersionBuf = 0;
1251 *pcchVersionBuf = 0;
1255 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
1257 DWORD lang = GetUserDefaultLangID();
1259 FIXME("Retrieve language from file\n");
1260 wsprintfW(tmp, szLangFormat, lang);
1261 lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
1262 *pcchLangBuf = lstrlenW(lpLangBuf);
1265 end:
1266 HeapFree(GetProcessHeap(), 0, lpVer);
1267 return ret;
1271 /******************************************************************
1272 * DllMain
1274 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
1276 switch(fdwReason)
1278 case DLL_PROCESS_ATTACH:
1279 msi_hInstance = hinstDLL;
1280 DisableThreadLibraryCalls(hinstDLL);
1281 msi_dialog_register_class();
1282 break;
1283 case DLL_PROCESS_DETACH:
1284 msi_dialog_unregister_class();
1285 /* FIXME: Cleanup */
1286 break;
1288 return TRUE;
1291 typedef struct tagIClassFactoryImpl
1293 const IClassFactoryVtbl *lpVtbl;
1294 } IClassFactoryImpl;
1296 static HRESULT WINAPI MsiCF_QueryInterface(LPCLASSFACTORY iface,
1297 REFIID riid,LPVOID *ppobj)
1299 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1300 FIXME("%p %s %p\n",This,debugstr_guid(riid),ppobj);
1301 return E_NOINTERFACE;
1304 static ULONG WINAPI MsiCF_AddRef(LPCLASSFACTORY iface)
1306 return 2;
1309 static ULONG WINAPI MsiCF_Release(LPCLASSFACTORY iface)
1311 return 1;
1314 static HRESULT WINAPI MsiCF_CreateInstance(LPCLASSFACTORY iface,
1315 LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
1317 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1319 FIXME("%p %p %s %p\n", This, pOuter, debugstr_guid(riid), ppobj);
1320 return E_FAIL;
1323 static HRESULT WINAPI MsiCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
1325 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1327 FIXME("%p %d\n", This, dolock);
1328 return S_OK;
1331 static const IClassFactoryVtbl MsiCF_Vtbl =
1333 MsiCF_QueryInterface,
1334 MsiCF_AddRef,
1335 MsiCF_Release,
1336 MsiCF_CreateInstance,
1337 MsiCF_LockServer
1340 static IClassFactoryImpl Msi_CF = { &MsiCF_Vtbl };
1342 /******************************************************************
1343 * DllGetClassObject [MSI.@]
1345 HRESULT WINAPI MSI_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
1347 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
1349 if( IsEqualCLSID (rclsid, &CLSID_IMsiServer) ||
1350 IsEqualCLSID (rclsid, &CLSID_IMsiServerMessage) ||
1351 IsEqualCLSID (rclsid, &CLSID_IMsiServerX1) ||
1352 IsEqualCLSID (rclsid, &CLSID_IMsiServerX2) ||
1353 IsEqualCLSID (rclsid, &CLSID_IMsiServerX3) )
1355 *ppv = (LPVOID) &Msi_CF;
1356 return S_OK;
1358 return CLASS_E_CLASSNOTAVAILABLE;
1361 /******************************************************************
1362 * DllGetVersion [MSI.@]
1364 HRESULT WINAPI MSI_DllGetVersion(DLLVERSIONINFO *pdvi)
1366 TRACE("%p\n",pdvi);
1368 if (pdvi->cbSize != sizeof(DLLVERSIONINFO))
1369 return E_INVALIDARG;
1371 pdvi->dwMajorVersion = MSI_MAJORVERSION;
1372 pdvi->dwMinorVersion = MSI_MINORVERSION;
1373 pdvi->dwBuildNumber = MSI_BUILDNUMBER;
1374 pdvi->dwPlatformID = 1;
1376 return S_OK;
1379 /******************************************************************
1380 * DllCanUnloadNow [MSI.@]
1382 BOOL WINAPI MSI_DllCanUnloadNow(void)
1384 return S_FALSE;
1387 UINT WINAPI MsiGetFeatureUsageW(LPCWSTR szProduct, LPCWSTR szFeature,
1388 DWORD* pdwUseCount, WORD* pwDateUsed)
1390 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
1391 pdwUseCount, pwDateUsed);
1392 return ERROR_CALL_NOT_IMPLEMENTED;
1395 UINT WINAPI MsiGetFeatureUsageA(LPCSTR szProduct, LPCSTR szFeature,
1396 DWORD* pdwUseCount, WORD* pwDateUsed)
1398 FIXME("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
1399 pdwUseCount, pwDateUsed);
1400 return ERROR_CALL_NOT_IMPLEMENTED;
1403 INSTALLSTATE WINAPI MsiUseFeatureExW(LPCWSTR szProduct, LPCWSTR szFeature,
1404 DWORD dwInstallMode, DWORD dwReserved)
1406 FIXME("%s %s %li %li\n", debugstr_w(szProduct), debugstr_w(szFeature),
1407 dwInstallMode, dwReserved);
1410 * Polls all the components of the feature to find install state and then
1411 * writes:
1412 * Software\\Microsoft\\Windows\\CurrentVersion\\
1413 * Installer\\Products\\<squishguid>\\<feature>
1414 * "Usage"=dword:........
1417 return INSTALLSTATE_LOCAL;
1420 /***********************************************************************
1421 * MsiUseFeatureExA [MSI.@]
1423 INSTALLSTATE WINAPI MsiUseFeatureExA(LPCSTR szProduct, LPCSTR szFeature,
1424 DWORD dwInstallMode, DWORD dwReserved)
1426 FIXME("%s %s %li %li\n", debugstr_a(szProduct), debugstr_a(szFeature),
1427 dwInstallMode, dwReserved);
1429 return INSTALLSTATE_LOCAL;
1432 INSTALLSTATE WINAPI MsiUseFeatureW(LPCWSTR szProduct, LPCWSTR szFeature)
1434 FIXME("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
1436 return INSTALLSTATE_LOCAL;
1439 INSTALLSTATE WINAPI MsiUseFeatureA(LPCSTR szProduct, LPCSTR szFeature)
1441 FIXME("%s %s\n", debugstr_a(szProduct), debugstr_a(szFeature));
1443 return INSTALLSTATE_LOCAL;
1446 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
1447 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR szProduct,
1448 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
1449 DWORD* pcchPathBuf)
1451 HKEY hkey;
1452 UINT rc;
1453 LPWSTR info;
1454 DWORD sz;
1455 LPWSTR product = NULL;
1456 LPWSTR component = NULL;
1457 LPWSTR ptr;
1458 GUID clsid;
1460 TRACE("%s %s %li %s %li %li %p %p\n", debugstr_w(szComponent),
1461 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
1462 Unused1, Unused2, lpPathBuf, pcchPathBuf);
1464 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
1465 if (rc != ERROR_SUCCESS)
1466 return ERROR_INDEX_ABSENT;
1468 sz = 0;
1469 rc = RegQueryValueExW( hkey, szQualifier, NULL, NULL, NULL, &sz);
1470 if (sz <= 0)
1472 RegCloseKey(hkey);
1473 return ERROR_INDEX_ABSENT;
1476 info = HeapAlloc(GetProcessHeap(),0,sz);
1477 rc = RegQueryValueExW( hkey, szQualifier, NULL, NULL, (LPBYTE)info, &sz);
1478 if (rc != ERROR_SUCCESS)
1480 RegCloseKey(hkey);
1481 HeapFree(GetProcessHeap(),0,info);
1482 return ERROR_INDEX_ABSENT;
1485 /* find the component */
1486 ptr = strchrW(&info[20],'>');
1487 if (ptr)
1488 ptr++;
1489 else
1491 RegCloseKey(hkey);
1492 HeapFree(GetProcessHeap(),0,info);
1493 return ERROR_INDEX_ABSENT;
1496 if (!szProduct)
1498 decode_base85_guid(info,&clsid);
1499 StringFromCLSID(&clsid, &product);
1501 decode_base85_guid(ptr,&clsid);
1502 StringFromCLSID(&clsid, &component);
1504 if (!szProduct)
1505 rc = MsiGetComponentPathW(product, component, lpPathBuf, pcchPathBuf);
1506 else
1507 rc = MsiGetComponentPathW(szProduct, component, lpPathBuf, pcchPathBuf);
1509 RegCloseKey(hkey);
1510 HeapFree(GetProcessHeap(),0,info);
1511 HeapFree(GetProcessHeap(),0,product);
1512 HeapFree(GetProcessHeap(),0,component);
1514 if (rc == INSTALLSTATE_LOCAL)
1515 return ERROR_SUCCESS;
1516 else
1517 return ERROR_FILE_NOT_FOUND;
1520 /***********************************************************************
1521 * MsiProvideQualifiedComponentW [MSI.@]
1523 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
1524 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
1525 DWORD* pcchPathBuf)
1527 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
1528 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
1531 /***********************************************************************
1532 * MsiProvideQualifiedComponentA [MSI.@]
1534 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
1535 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
1536 DWORD* pcchPathBuf)
1538 LPWSTR szwComponent, szwQualifier, lpwPathBuf;
1539 DWORD pcchwPathBuf;
1540 UINT rc;
1542 TRACE("%s %s %li %p %p\n",szComponent, szQualifier,
1543 dwInstallMode, lpPathBuf, pcchPathBuf);
1545 szwComponent= strdupAtoW( szComponent);
1546 szwQualifier= strdupAtoW( szQualifier);
1548 lpwPathBuf = HeapAlloc(GetProcessHeap(),0,*pcchPathBuf * sizeof(WCHAR));
1550 pcchwPathBuf = *pcchPathBuf;
1552 rc = MsiProvideQualifiedComponentW(szwComponent, szwQualifier,
1553 dwInstallMode, lpwPathBuf, &pcchwPathBuf);
1555 HeapFree(GetProcessHeap(),0,szwComponent);
1556 HeapFree(GetProcessHeap(),0,szwQualifier);
1557 *pcchPathBuf = WideCharToMultiByte(CP_ACP, 0, lpwPathBuf, pcchwPathBuf,
1558 lpPathBuf, *pcchPathBuf, NULL, NULL);
1560 HeapFree(GetProcessHeap(),0,lpwPathBuf);
1561 return rc;
1564 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct, LPWSTR lpUserNameBuf,
1565 DWORD* pcchUserNameBuf, LPWSTR lpOrgNameBuf,
1566 DWORD* pcchOrgNameBuf, LPWSTR lpSerialBuf, DWORD* pcchSerialBuf)
1568 HKEY hkey;
1569 DWORD sz;
1570 UINT rc = ERROR_SUCCESS,rc2 = ERROR_SUCCESS;
1572 TRACE("%s %p %p %p %p %p %p\n",debugstr_w(szProduct), lpUserNameBuf,
1573 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
1574 pcchSerialBuf);
1576 rc = MSIREG_OpenUninstallKey(szProduct, &hkey, FALSE);
1577 if (rc != ERROR_SUCCESS)
1578 return USERINFOSTATE_UNKNOWN;
1580 if (lpUserNameBuf)
1582 sz = *lpUserNameBuf * sizeof(WCHAR);
1583 rc = RegQueryValueExW( hkey, INSTALLPROPERTY_REGOWNERstringW, NULL,
1584 NULL, (LPBYTE)lpUserNameBuf,
1585 &sz);
1587 if (!lpUserNameBuf && pcchUserNameBuf)
1589 sz = 0;
1590 rc = RegQueryValueExW( hkey, INSTALLPROPERTY_REGOWNERstringW, NULL,
1591 NULL, NULL, &sz);
1594 if (pcchUserNameBuf)
1595 *pcchUserNameBuf = sz / sizeof(WCHAR);
1597 if (lpOrgNameBuf)
1599 sz = *pcchOrgNameBuf * sizeof(WCHAR);
1600 rc2 = RegQueryValueExW( hkey, INSTALLPROPERTY_REGCOMPANYstringW, NULL,
1601 NULL, (LPBYTE)lpOrgNameBuf, &sz);
1603 if (!lpOrgNameBuf && pcchOrgNameBuf)
1605 sz = 0;
1606 rc2 = RegQueryValueExW( hkey, INSTALLPROPERTY_REGCOMPANYstringW, NULL,
1607 NULL, NULL, &sz);
1610 if (pcchOrgNameBuf)
1611 *pcchOrgNameBuf = sz / sizeof(WCHAR);
1613 if (rc != ERROR_SUCCESS && rc != ERROR_MORE_DATA &&
1614 rc2 != ERROR_SUCCESS && rc2 != ERROR_MORE_DATA)
1616 RegCloseKey(hkey);
1617 return USERINFOSTATE_ABSENT;
1620 if (lpSerialBuf)
1622 sz = *pcchSerialBuf * sizeof(WCHAR);
1623 RegQueryValueExW( hkey, INSTALLPROPERTY_PRODUCTIDstringW, NULL, NULL,
1624 (LPBYTE)lpSerialBuf, &sz);
1626 if (!lpSerialBuf && pcchSerialBuf)
1628 sz = 0;
1629 rc = RegQueryValueExW( hkey, INSTALLPROPERTY_PRODUCTIDstringW, NULL,
1630 NULL, NULL, &sz);
1632 if (pcchSerialBuf)
1633 *pcchSerialBuf = sz / sizeof(WCHAR);
1635 RegCloseKey(hkey);
1636 return USERINFOSTATE_PRESENT;
1639 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct, LPSTR lpUserNameBuf,
1640 DWORD* pcchUserNameBuf, LPSTR lpOrgNameBuf,
1641 DWORD* pcchOrgNameBuf, LPSTR lpSerialBuf, DWORD* pcchSerialBuf)
1643 FIXME("%s %p %p %p %p %p %p\n",debugstr_a(szProduct), lpUserNameBuf,
1644 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
1645 pcchSerialBuf);
1647 return USERINFOSTATE_UNKNOWN;
1650 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
1652 MSIHANDLE handle;
1653 UINT rc;
1654 MSIPACKAGE *package;
1655 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
1657 TRACE("(%s)\n",debugstr_w(szProduct));
1659 rc = MsiOpenProductW(szProduct,&handle);
1660 if (rc != ERROR_SUCCESS)
1661 return ERROR_INVALID_PARAMETER;
1663 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
1664 rc = ACTION_PerformUIAction(package, szFirstRun);
1665 msiobj_release( &package->hdr );
1667 MsiCloseHandle(handle);
1669 return rc;
1672 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
1674 MSIHANDLE handle;
1675 UINT rc;
1676 MSIPACKAGE *package;
1677 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
1679 TRACE("(%s)\n",debugstr_a(szProduct));
1681 rc = MsiOpenProductA(szProduct,&handle);
1682 if (rc != ERROR_SUCCESS)
1683 return ERROR_INVALID_PARAMETER;
1685 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
1686 rc = ACTION_PerformUIAction(package, szFirstRun);
1687 msiobj_release( &package->hdr );
1689 MsiCloseHandle(handle);
1691 return rc;
1694 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
1696 WCHAR path[MAX_PATH];
1698 if(dwReserved) {
1699 FIXME("Don't know how to handle argument %ld\n", dwReserved);
1700 return ERROR_CALL_NOT_IMPLEMENTED;
1703 if(!GetWindowsDirectoryW(path, MAX_PATH)) {
1704 FIXME("GetWindowsDirectory failed unexpected! Error %ld\n",
1705 GetLastError());
1706 return ERROR_CALL_NOT_IMPLEMENTED;
1709 strcatW(path, installerW);
1711 CreateDirectoryW(path, NULL);
1713 return 0;
1716 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
1717 LPSTR szProductCode, LPSTR szFeatureId,
1718 LPSTR szComponentCode )
1720 FIXME("\n");
1721 return ERROR_CALL_NOT_IMPLEMENTED;
1724 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
1725 LPWSTR szProductCode, LPWSTR szFeatureId,
1726 LPWSTR szComponentCode )
1728 FIXME("\n");
1729 return ERROR_CALL_NOT_IMPLEMENTED;
1732 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
1733 DWORD dwReinstallMode )
1735 FIXME("%s %s %li\n", debugstr_w(szProduct), debugstr_w(szFeature),
1736 dwReinstallMode);
1737 return ERROR_SUCCESS;
1740 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
1741 DWORD dwReinstallMode )
1743 FIXME("%s %s %li\n", debugstr_a(szProduct), debugstr_a(szFeature),
1744 dwReinstallMode);
1745 return ERROR_SUCCESS;