4 * Copyright 2004 Huw D M Davies
5 * Copyright 2005 Sami Aario
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "advpack_private.h"
24 typedef HRESULT (WINAPI
*DLLREGISTER
) (void);
26 #define MAX_FIELD_LENGTH 512
29 /* registry path of the Installed Components key for per-user stubs */
30 static const WCHAR setup_key
[] = {
31 'S','O','F','T','W','A','R','E','\\',
32 'M','i','c','r','o','s','o','f','t','\\',
33 'A','c','t','i','v','e',' ','S','e','t','u','p','\\',
34 'I','n','s','t','a','l','l','e','d',' ',
35 'C','o','m','p','o','n','e','n','t','s',0
38 /* Strip single quotes from a token - note size includes NULL */
39 static void strip_quotes(WCHAR
*buffer
, DWORD
*size
)
41 if (buffer
[0] == '\'' && (*size
> 1) && buffer
[*size
-2]=='\'')
45 memmove(buffer
, buffer
+ 1, *size
* sizeof(WCHAR
));
49 /* parses the destination directory parameters from pszSection
50 * the parameters are of the form: root,key,value,unknown,fallback
51 * we first read the reg value root\\key\\value and if that fails,
52 * use fallback as the destination directory
54 static void get_dest_dir(HINF hInf
, PCWSTR pszSection
, PWSTR pszBuffer
, DWORD dwSize
)
57 WCHAR key
[MAX_PATH
+ 2], value
[MAX_PATH
+ 2];
58 WCHAR prefix
[PREFIX_LEN
+ 2];
59 HKEY root
, subkey
= 0;
62 static const WCHAR hklm
[] = {'H','K','L','M',0};
63 static const WCHAR hkcu
[] = {'H','K','C','U',0};
65 /* load the destination parameters */
66 SetupFindFirstLineW(hInf
, pszSection
, NULL
, &context
);
67 SetupGetStringFieldW(&context
, 1, prefix
, PREFIX_LEN
+ 2, &size
);
68 strip_quotes(prefix
, &size
);
69 SetupGetStringFieldW(&context
, 2, key
, MAX_PATH
+ 2, &size
);
70 strip_quotes(key
, &size
);
71 SetupGetStringFieldW(&context
, 3, value
, MAX_PATH
+ 2, &size
);
72 strip_quotes(value
, &size
);
74 if (!lstrcmpW(prefix
, hklm
))
75 root
= HKEY_LOCAL_MACHINE
;
76 else if (!lstrcmpW(prefix
, hkcu
))
77 root
= HKEY_CURRENT_USER
;
81 size
= dwSize
* sizeof(WCHAR
);
83 /* fallback to the default destination dir if reg fails */
84 if (RegOpenKeyW(root
, key
, &subkey
) ||
85 RegQueryValueExW(subkey
, value
, NULL
, NULL
, (LPBYTE
)pszBuffer
, &size
))
87 SetupGetStringFieldW(&context
, 5, pszBuffer
, dwSize
, &size
);
88 strip_quotes(pszBuffer
, &size
);
91 if (subkey
) RegCloseKey(subkey
);
94 /* loads the LDIDs specified in the install section of an INF */
95 void set_ldids(HINF hInf
, LPCWSTR pszInstallSection
, LPCWSTR pszWorkingDir
)
97 WCHAR field
[MAX_FIELD_LENGTH
];
98 WCHAR line
[MAX_FIELD_LENGTH
];
104 static const WCHAR source_dir
[] = {'S','o','u','r','c','e','D','i','r',0};
106 static const WCHAR custDestW
[] = {
107 'C','u','s','t','o','m','D','e','s','t','i','n','a','t','i','o','n',0
110 if (!SetupGetLineTextW(NULL
, hInf
, pszInstallSection
, custDestW
,
111 field
, MAX_FIELD_LENGTH
, &size
))
114 if (!SetupFindFirstLineW(hInf
, field
, NULL
, &context
))
119 LPWSTR value
, ptr
, key
, key_copy
= NULL
;
122 SetupGetLineTextW(&context
, NULL
, NULL
, NULL
,
123 line
, MAX_FIELD_LENGTH
, &size
);
125 /* SetupGetLineTextW returns the value if there is only one key, but
126 * returns the whole line if there is more than one key
128 if (!(value
= strchrW(line
, '=')))
130 SetupGetStringFieldW(&context
, 0, NULL
, 0, &size
);
131 key
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
133 SetupGetStringFieldW(&context
, 0, key
, size
, &size
);
142 /* remove leading whitespace from the value */
143 while (*value
== ' ')
146 /* Extract the flags */
147 ptr
= strchrW(value
, ',');
150 flags
= atolW(ptr
+1);
153 /* set dest to pszWorkingDir if key is SourceDir */
154 if (pszWorkingDir
&& !lstrcmpiW(value
, source_dir
))
155 lstrcpynW(dest
, pszWorkingDir
, MAX_PATH
);
157 get_dest_dir(hInf
, value
, dest
, MAX_PATH
);
159 /* If prompting required, provide dialog to request path */
161 FIXME("Need to support changing paths - default will be used\n");
163 /* set all ldids to dest */
164 while ((ptr
= get_parameter(&key
, ',', FALSE
)))
167 SetupSetDirectoryIdW(hInf
, ldid
, dest
);
169 HeapFree(GetProcessHeap(), 0, key_copy
);
170 } while (SetupFindNextLine(&context
, &context
));
173 /***********************************************************************
174 * CloseINFEngine (ADVPACK.@)
176 * Closes a handle to an INF file opened with OpenINFEngine.
179 * hInf [I] Handle to the INF file to close.
185 HRESULT WINAPI
CloseINFEngine(HINF hInf
)
187 TRACE("(%p)\n", hInf
);
192 SetupCloseInfFile(hInf
);
196 /***********************************************************************
197 * IsNTAdmin (ADVPACK.@)
199 * Checks if the user has admin privileges.
202 * reserved [I] Reserved. Must be 0.
203 * pReserved [I] Reserved. Must be NULL.
206 * TRUE if user has admin rights, FALSE otherwise.
208 BOOL WINAPI
IsNTAdmin(DWORD reserved
, LPDWORD pReserved
)
210 SID_IDENTIFIER_AUTHORITY SidAuthority
= {SECURITY_NT_AUTHORITY
};
211 PTOKEN_GROUPS pTokenGroups
;
212 BOOL bSidFound
= FALSE
;
217 TRACE("(%d, %p)\n", reserved
, pReserved
);
219 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &hToken
))
222 if (!GetTokenInformation(hToken
, TokenGroups
, NULL
, 0, &dwSize
))
224 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
231 pTokenGroups
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
238 if (!GetTokenInformation(hToken
, TokenGroups
, pTokenGroups
, dwSize
, &dwSize
))
240 HeapFree(GetProcessHeap(), 0, pTokenGroups
);
247 if (!AllocateAndInitializeSid(&SidAuthority
, 2, SECURITY_BUILTIN_DOMAIN_RID
,
248 DOMAIN_ALIAS_RID_ADMINS
, 0, 0, 0, 0, 0, 0, &pSid
))
250 HeapFree(GetProcessHeap(), 0, pTokenGroups
);
254 for (i
= 0; i
< pTokenGroups
->GroupCount
; i
++)
256 if (EqualSid(pSid
, pTokenGroups
->Groups
[i
].Sid
))
263 HeapFree(GetProcessHeap(), 0, pTokenGroups
);
269 /***********************************************************************
270 * NeedRebootInit (ADVPACK.@)
272 * Sets up conditions for reboot checking.
275 * Value required by NeedReboot.
277 DWORD WINAPI
NeedRebootInit(VOID
)
279 FIXME("(VOID): stub\n");
283 /***********************************************************************
284 * NeedReboot (ADVPACK.@)
286 * Determines whether a reboot is required.
289 * dwRebootCheck [I] Value from NeedRebootInit.
292 * TRUE if a reboot is needed, FALSE otherwise.
297 BOOL WINAPI
NeedReboot(DWORD dwRebootCheck
)
299 FIXME("(%d): stub\n", dwRebootCheck
);
303 /***********************************************************************
304 * OpenINFEngineA (ADVPACK.@)
306 * See OpenINFEngineW.
308 HRESULT WINAPI
OpenINFEngineA(LPCSTR pszInfFilename
, LPCSTR pszInstallSection
,
309 DWORD dwFlags
, HINF
*phInf
, PVOID pvReserved
)
311 UNICODE_STRING filenameW
, installW
;
314 TRACE("(%s, %s, %d, %p, %p)\n", debugstr_a(pszInfFilename
),
315 debugstr_a(pszInstallSection
), dwFlags
, phInf
, pvReserved
);
317 if (!pszInfFilename
|| !phInf
)
320 RtlCreateUnicodeStringFromAsciiz(&filenameW
, pszInfFilename
);
321 RtlCreateUnicodeStringFromAsciiz(&installW
, pszInstallSection
);
323 res
= OpenINFEngineW(filenameW
.Buffer
, installW
.Buffer
,
324 dwFlags
, phInf
, pvReserved
);
326 RtlFreeUnicodeString(&filenameW
);
327 RtlFreeUnicodeString(&installW
);
332 /***********************************************************************
333 * OpenINFEngineW (ADVPACK.@)
335 * Opens and returns a handle to an INF file to be used by
336 * TranslateInfStringEx to continuously translate the INF file.
339 * pszInfFilename [I] Filename of the INF to open.
340 * pszInstallSection [I] Name of the Install section in the INF.
341 * dwFlags [I] See advpub.h.
342 * phInf [O] Handle to the loaded INF file.
343 * pvReserved [I] Reserved. Must be NULL.
349 HRESULT WINAPI
OpenINFEngineW(LPCWSTR pszInfFilename
, LPCWSTR pszInstallSection
,
350 DWORD dwFlags
, HINF
*phInf
, PVOID pvReserved
)
352 TRACE("(%s, %s, %d, %p, %p)\n", debugstr_w(pszInfFilename
),
353 debugstr_w(pszInstallSection
), dwFlags
, phInf
, pvReserved
);
355 if (!pszInfFilename
|| !phInf
)
358 *phInf
= SetupOpenInfFileW(pszInfFilename
, NULL
, INF_STYLE_WIN4
, NULL
);
359 if (*phInf
== INVALID_HANDLE_VALUE
)
360 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
362 set_ldids(*phInf
, pszInstallSection
, NULL
);
367 /***********************************************************************
368 * RebootCheckOnInstallA (ADVPACK.@)
370 * See RebootCheckOnInstallW.
372 HRESULT WINAPI
RebootCheckOnInstallA(HWND hWnd
, LPCSTR pszINF
,
373 LPCSTR pszSec
, DWORD dwReserved
)
375 UNICODE_STRING infW
, secW
;
378 TRACE("(%p, %s, %s, %d)\n", hWnd
, debugstr_a(pszINF
),
379 debugstr_a(pszSec
), dwReserved
);
381 if (!pszINF
|| !pszSec
)
384 RtlCreateUnicodeStringFromAsciiz(&infW
, pszINF
);
385 RtlCreateUnicodeStringFromAsciiz(&secW
, pszSec
);
387 res
= RebootCheckOnInstallW(hWnd
, infW
.Buffer
, secW
.Buffer
, dwReserved
);
389 RtlFreeUnicodeString(&infW
);
390 RtlFreeUnicodeString(&secW
);
395 /***********************************************************************
396 * RebootCheckOnInstallW (ADVPACK.@)
398 * Checks if a reboot is required for an installed INF section.
401 * hWnd [I] Handle to the window used for messages.
402 * pszINF [I] Filename of the INF file.
403 * pszSec [I] INF section to check.
404 * dwReserved [I] Reserved. Must be 0.
407 * Success: S_OK - Reboot is needed if the INF section is installed.
408 * S_FALSE - Reboot is not needed.
409 * Failure: HRESULT of GetLastError().
412 * if pszSec is NULL, RebootCheckOnInstall checks the DefaultInstall
413 * or DefaultInstall.NT section.
418 HRESULT WINAPI
RebootCheckOnInstallW(HWND hWnd
, LPCWSTR pszINF
,
419 LPCWSTR pszSec
, DWORD dwReserved
)
421 FIXME("(%p, %s, %s, %d): stub\n", hWnd
, debugstr_w(pszINF
),
422 debugstr_w(pszSec
), dwReserved
);
427 /* registers the OCX if do_reg is TRUE, unregisters it otherwise */
428 HRESULT
do_ocx_reg(HMODULE hocx
, BOOL do_reg
, const WCHAR
*flags
, const WCHAR
*param
)
430 DLLREGISTER reg_func
;
433 reg_func
= (DLLREGISTER
)GetProcAddress(hocx
, "DllRegisterServer");
435 reg_func
= (DLLREGISTER
)GetProcAddress(hocx
, "DllUnregisterServer");
444 /***********************************************************************
445 * RegisterOCX (ADVPACK.@)
450 * hWnd [I] Handle to the window used for the display.
451 * hInst [I] Instance of the process.
452 * cmdline [I] Contains parameters in the order OCX,flags,param.
453 * show [I] How the window should be shown.
460 * OCX - Filename of the OCX to register.
461 * flags - Controls the operation of RegisterOCX.
462 * 'I' Call DllRegisterServer and DllInstall.
463 * 'N' Only call DllInstall.
464 * param - Command line passed to DllInstall.
466 HRESULT WINAPI
RegisterOCX(HWND hWnd
, HINSTANCE hInst
, LPCSTR cmdline
, INT show
)
468 LPWSTR ocx_filename
, str_flags
, param
;
469 LPWSTR cmdline_copy
, cmdline_ptr
;
470 UNICODE_STRING cmdlineW
;
475 TRACE("(%s)\n", debugstr_a(cmdline
));
477 RtlCreateUnicodeStringFromAsciiz(&cmdlineW
, cmdline
);
479 size
= (lstrlenW(cmdlineW
.Buffer
) + 1) * sizeof(WCHAR
);
480 cmdline_copy
= HeapAlloc(GetProcessHeap(), 0, size
);
481 cmdline_ptr
= cmdline_copy
;
482 lstrcpyW(cmdline_copy
, cmdlineW
.Buffer
);
484 ocx_filename
= get_parameter(&cmdline_ptr
, ',', TRUE
);
485 if (!ocx_filename
|| !*ocx_filename
)
488 str_flags
= get_parameter(&cmdline_ptr
, ',', TRUE
);
489 param
= get_parameter(&cmdline_ptr
, ',', TRUE
);
491 hm
= LoadLibraryExW(ocx_filename
, NULL
, LOAD_WITH_ALTERED_SEARCH_PATH
);
495 hr
= do_ocx_reg(hm
, TRUE
, str_flags
, param
);
499 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
500 RtlFreeUnicodeString(&cmdlineW
);
505 /***********************************************************************
506 * SetPerUserSecValuesA (ADVPACK.@)
508 * See SetPerUserSecValuesW.
510 HRESULT WINAPI
SetPerUserSecValuesA(PERUSERSECTIONA
* pPerUser
)
512 PERUSERSECTIONW perUserW
;
514 TRACE("(%p)\n", pPerUser
);
519 MultiByteToWideChar(CP_ACP
, 0, pPerUser
->szGUID
, -1, perUserW
.szGUID
,
520 sizeof(perUserW
.szGUID
) / sizeof(WCHAR
));
521 MultiByteToWideChar(CP_ACP
, 0, pPerUser
->szDispName
, -1, perUserW
.szDispName
,
522 sizeof(perUserW
.szDispName
) / sizeof(WCHAR
));
523 MultiByteToWideChar(CP_ACP
, 0, pPerUser
->szLocale
, -1, perUserW
.szLocale
,
524 sizeof(perUserW
.szLocale
) / sizeof(WCHAR
));
525 MultiByteToWideChar(CP_ACP
, 0, pPerUser
->szStub
, -1, perUserW
.szStub
,
526 sizeof(perUserW
.szStub
) / sizeof(WCHAR
));
527 MultiByteToWideChar(CP_ACP
, 0, pPerUser
->szVersion
, -1, perUserW
.szVersion
,
528 sizeof(perUserW
.szVersion
) / sizeof(WCHAR
));
529 MultiByteToWideChar(CP_ACP
, 0, pPerUser
->szCompID
, -1, perUserW
.szCompID
,
530 sizeof(perUserW
.szCompID
) / sizeof(WCHAR
));
531 perUserW
.dwIsInstalled
= pPerUser
->dwIsInstalled
;
532 perUserW
.bRollback
= pPerUser
->bRollback
;
534 return SetPerUserSecValuesW(&perUserW
);
537 /***********************************************************************
538 * SetPerUserSecValuesW (ADVPACK.@)
540 * Prepares the per-user stub values under IsInstalled\{GUID} that
541 * control the per-user installation.
544 * pPerUser [I] Per-user stub values.
550 HRESULT WINAPI
SetPerUserSecValuesW(PERUSERSECTIONW
* pPerUser
)
554 static const WCHAR stub_path
[] = {'S','t','u','b','P','a','t','h',0};
555 static const WCHAR version
[] = {'V','e','r','s','i','o','n',0};
556 static const WCHAR locale
[] = {'L','o','c','a','l','e',0};
557 static const WCHAR compid
[] = {'C','o','m','p','o','n','e','n','t','I','D',0};
558 static const WCHAR isinstalled
[] = {'I','s','I','n','s','t','a','l','l','e','d',0};
560 TRACE("(%p)\n", pPerUser
);
562 if (!pPerUser
|| !*pPerUser
->szGUID
)
565 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
, setup_key
, 0, NULL
, 0, KEY_WRITE
,
571 if (RegCreateKeyExW(setup
, pPerUser
->szGUID
, 0, NULL
, 0, KEY_ALL_ACCESS
,
578 if (*pPerUser
->szStub
)
580 RegSetValueExW(guid
, stub_path
, 0, REG_SZ
, (LPBYTE
)pPerUser
->szStub
,
581 (lstrlenW(pPerUser
->szStub
) + 1) * sizeof(WCHAR
));
584 if (*pPerUser
->szVersion
)
586 RegSetValueExW(guid
, version
, 0, REG_SZ
, (LPBYTE
)pPerUser
->szVersion
,
587 (lstrlenW(pPerUser
->szVersion
) + 1) * sizeof(WCHAR
));
590 if (*pPerUser
->szLocale
)
592 RegSetValueExW(guid
, locale
, 0, REG_SZ
, (LPBYTE
)pPerUser
->szLocale
,
593 (lstrlenW(pPerUser
->szLocale
) + 1) * sizeof(WCHAR
));
596 if (*pPerUser
->szCompID
)
598 RegSetValueExW(guid
, compid
, 0, REG_SZ
, (LPBYTE
)pPerUser
->szCompID
,
599 (lstrlenW(pPerUser
->szCompID
) + 1) * sizeof(WCHAR
));
602 if (*pPerUser
->szDispName
)
604 RegSetValueExW(guid
, NULL
, 0, REG_SZ
, (LPBYTE
)pPerUser
->szDispName
,
605 (lstrlenW(pPerUser
->szDispName
) + 1) * sizeof(WCHAR
));
608 RegSetValueExW(guid
, isinstalled
, 0, REG_DWORD
,
609 (LPBYTE
)&pPerUser
->dwIsInstalled
, sizeof(DWORD
));
617 /***********************************************************************
618 * TranslateInfStringA (ADVPACK.@)
620 * See TranslateInfStringW.
622 HRESULT WINAPI
TranslateInfStringA(LPCSTR pszInfFilename
, LPCSTR pszInstallSection
,
623 LPCSTR pszTranslateSection
, LPCSTR pszTranslateKey
, LPSTR pszBuffer
,
624 DWORD dwBufferSize
, PDWORD pdwRequiredSize
, PVOID pvReserved
)
626 UNICODE_STRING filenameW
, installW
;
627 UNICODE_STRING translateW
, keyW
;
632 TRACE("(%s, %s, %s, %s, %p, %d, %p, %p)\n",
633 debugstr_a(pszInfFilename
), debugstr_a(pszInstallSection
),
634 debugstr_a(pszTranslateSection
), debugstr_a(pszTranslateKey
),
635 pszBuffer
, dwBufferSize
,pdwRequiredSize
, pvReserved
);
637 if (!pszInfFilename
|| !pszTranslateSection
||
638 !pszTranslateKey
|| !pdwRequiredSize
)
641 RtlCreateUnicodeStringFromAsciiz(&filenameW
, pszInfFilename
);
642 RtlCreateUnicodeStringFromAsciiz(&installW
, pszInstallSection
);
643 RtlCreateUnicodeStringFromAsciiz(&translateW
, pszTranslateSection
);
644 RtlCreateUnicodeStringFromAsciiz(&keyW
, pszTranslateKey
);
646 res
= TranslateInfStringW(filenameW
.Buffer
, installW
.Buffer
,
647 translateW
.Buffer
, keyW
.Buffer
, NULL
,
648 dwBufferSize
, &len
, NULL
);
652 bufferW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
654 res
= TranslateInfStringW(filenameW
.Buffer
, installW
.Buffer
,
655 translateW
.Buffer
, keyW
.Buffer
, bufferW
,
659 *pdwRequiredSize
= WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1,
660 NULL
, 0, NULL
, NULL
);
662 if (dwBufferSize
>= *pdwRequiredSize
)
664 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, pszBuffer
,
665 dwBufferSize
, NULL
, NULL
);
668 res
= E_NOT_SUFFICIENT_BUFFER
;
671 HeapFree(GetProcessHeap(), 0, bufferW
);
674 RtlFreeUnicodeString(&filenameW
);
675 RtlFreeUnicodeString(&installW
);
676 RtlFreeUnicodeString(&translateW
);
677 RtlFreeUnicodeString(&keyW
);
682 /***********************************************************************
683 * TranslateInfStringW (ADVPACK.@)
685 * Translates the value of a specified key in an inf file into the
686 * current locale by expanding string macros.
689 * pszInfFilename [I] Filename of the inf file.
690 * pszInstallSection [I]
691 * pszTranslateSection [I] Inf section where the key exists.
692 * pszTranslateKey [I] Key to translate.
693 * pszBuffer [O] Contains the translated string on exit.
694 * dwBufferSize [I] Size on input of pszBuffer.
695 * pdwRequiredSize [O] Length of the translated key.
696 * pvReserved [I] Reserved, must be NULL.
700 * Failure: An hresult error code.
702 HRESULT WINAPI
TranslateInfStringW(LPCWSTR pszInfFilename
, LPCWSTR pszInstallSection
,
703 LPCWSTR pszTranslateSection
, LPCWSTR pszTranslateKey
, LPWSTR pszBuffer
,
704 DWORD dwBufferSize
, PDWORD pdwRequiredSize
, PVOID pvReserved
)
709 TRACE("(%s, %s, %s, %s, %p, %d, %p, %p)\n",
710 debugstr_w(pszInfFilename
), debugstr_w(pszInstallSection
),
711 debugstr_w(pszTranslateSection
), debugstr_w(pszTranslateKey
),
712 pszBuffer
, dwBufferSize
,pdwRequiredSize
, pvReserved
);
714 if (!pszInfFilename
|| !pszTranslateSection
||
715 !pszTranslateKey
|| !pdwRequiredSize
)
718 hInf
= SetupOpenInfFileW(pszInfFilename
, NULL
, INF_STYLE_WIN4
, NULL
);
719 if (hInf
== INVALID_HANDLE_VALUE
)
720 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
722 set_ldids(hInf
, pszInstallSection
, NULL
);
724 if (!SetupGetLineTextW(NULL
, hInf
, pszTranslateSection
, pszTranslateKey
,
725 pszBuffer
, dwBufferSize
, pdwRequiredSize
))
727 if (dwBufferSize
< *pdwRequiredSize
)
728 hret
= E_NOT_SUFFICIENT_BUFFER
;
730 hret
= SPAPI_E_LINE_NOT_FOUND
;
733 SetupCloseInfFile(hInf
);
737 /***********************************************************************
738 * TranslateInfStringExA (ADVPACK.@)
740 * See TranslateInfStringExW.
742 HRESULT WINAPI
TranslateInfStringExA(HINF hInf
, LPCSTR pszInfFilename
,
743 LPCSTR pszTranslateSection
, LPCSTR pszTranslateKey
,
744 LPSTR pszBuffer
, DWORD dwBufferSize
,
745 PDWORD pdwRequiredSize
, PVOID pvReserved
)
747 UNICODE_STRING filenameW
, sectionW
, keyW
;
752 TRACE("(%p, %s, %s, %s, %p, %d, %p, %p)\n", hInf
, debugstr_a(pszInfFilename
),
753 debugstr_a(pszTranslateSection
), debugstr_a(pszTranslateKey
),
754 pszBuffer
, dwBufferSize
, pdwRequiredSize
, pvReserved
);
756 if (!pszInfFilename
|| !pszTranslateSection
||
757 !pszTranslateKey
|| !pdwRequiredSize
)
760 RtlCreateUnicodeStringFromAsciiz(&filenameW
, pszInfFilename
);
761 RtlCreateUnicodeStringFromAsciiz(§ionW
, pszTranslateSection
);
762 RtlCreateUnicodeStringFromAsciiz(&keyW
, pszTranslateKey
);
764 res
= TranslateInfStringExW(hInf
, filenameW
.Buffer
, sectionW
.Buffer
,
765 keyW
.Buffer
, NULL
, 0, &len
, NULL
);
769 bufferW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
771 res
= TranslateInfStringExW(hInf
, filenameW
.Buffer
, sectionW
.Buffer
,
772 keyW
.Buffer
, bufferW
, len
, &len
, NULL
);
776 *pdwRequiredSize
= WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1,
777 NULL
, 0, NULL
, NULL
);
779 if (dwBufferSize
>= *pdwRequiredSize
)
781 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, pszBuffer
,
782 dwBufferSize
, NULL
, NULL
);
785 res
= E_NOT_SUFFICIENT_BUFFER
;
788 HeapFree(GetProcessHeap(), 0, bufferW
);
791 RtlFreeUnicodeString(&filenameW
);
792 RtlFreeUnicodeString(§ionW
);
793 RtlFreeUnicodeString(&keyW
);
798 /***********************************************************************
799 * TranslateInfStringExW (ADVPACK.@)
801 * Using a handle to an INF file opened with OpenINFEngine, translates
802 * the value of a specified key in an inf file into the current locale
803 * by expanding string macros.
806 * hInf [I] Handle to the INF file.
807 * pszInfFilename [I] Filename of the INF file.
808 * pszTranslateSection [I] Inf section where the key exists.
809 * pszTranslateKey [I] Key to translate.
810 * pszBuffer [O] Contains the translated string on exit.
811 * dwBufferSize [I] Size on input of pszBuffer.
812 * pdwRequiredSize [O] Length of the translated key.
813 * pvReserved [I] Reserved. Must be NULL.
820 * To use TranslateInfStringEx to translate an INF file continuously,
821 * open the INF file with OpenINFEngine, call TranslateInfStringEx as
822 * many times as needed, then release the handle with CloseINFEngine.
823 * When translating more than one keys, this method is more efficient
824 * than calling TranslateInfString, because the INF file is only
827 HRESULT WINAPI
TranslateInfStringExW(HINF hInf
, LPCWSTR pszInfFilename
,
828 LPCWSTR pszTranslateSection
, LPCWSTR pszTranslateKey
,
829 LPWSTR pszBuffer
, DWORD dwBufferSize
,
830 PDWORD pdwRequiredSize
, PVOID pvReserved
)
832 TRACE("(%p, %s, %s, %s, %p, %d, %p, %p)\n", hInf
, debugstr_w(pszInfFilename
),
833 debugstr_w(pszTranslateSection
), debugstr_w(pszTranslateKey
),
834 pszBuffer
, dwBufferSize
, pdwRequiredSize
, pvReserved
);
836 if (!hInf
|| !pszInfFilename
|| !pszTranslateSection
|| !pszTranslateKey
)
839 if (!SetupGetLineTextW(NULL
, hInf
, pszTranslateSection
, pszTranslateKey
,
840 pszBuffer
, dwBufferSize
, pdwRequiredSize
))
842 if (dwBufferSize
< *pdwRequiredSize
)
843 return E_NOT_SUFFICIENT_BUFFER
;
845 return SPAPI_E_LINE_NOT_FOUND
;
851 /***********************************************************************
852 * UserInstStubWrapperA (ADVPACK.@)
854 * See UserInstStubWrapperW.
856 HRESULT WINAPI
UserInstStubWrapperA(HWND hWnd
, HINSTANCE hInstance
,
857 LPSTR pszParms
, INT nShow
)
859 UNICODE_STRING parmsW
;
862 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInstance
, debugstr_a(pszParms
), nShow
);
867 RtlCreateUnicodeStringFromAsciiz(&parmsW
, pszParms
);
869 res
= UserInstStubWrapperW(hWnd
, hInstance
, parmsW
.Buffer
, nShow
);
871 RtlFreeUnicodeString(&parmsW
);
876 /***********************************************************************
877 * UserInstStubWrapperW (ADVPACK.@)
879 * Launches the user stub wrapper specified by the RealStubPath
880 * registry value under Installed Components\szParms.
883 * hWnd [I] Handle to the window used for the display.
884 * hInstance [I] Instance of the process.
885 * szParms [I] The GUID of the installation.
886 * show [I] How the window should be shown.
893 * If the type of the StubRealPath value is REG_EXPAND_SZ, then
894 * we should call ExpandEnvironmentStrings on the value and
897 HRESULT WINAPI
UserInstStubWrapperW(HWND hWnd
, HINSTANCE hInstance
,
898 LPWSTR pszParms
, INT nShow
)
901 WCHAR stub
[MAX_PATH
];
902 DWORD size
= MAX_PATH
;
906 static const WCHAR real_stub_path
[] = {
907 'R','e','a','l','S','t','u','b','P','a','t','h',0
910 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInstance
, debugstr_w(pszParms
), nShow
);
912 if (!pszParms
|| !*pszParms
)
915 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, setup_key
, 0, KEY_READ
, &setup
))
920 if (RegOpenKeyExW(setup
, pszParms
, 0, KEY_READ
, &guid
))
926 res
= RegQueryValueExW(guid
, real_stub_path
, NULL
, NULL
, (LPBYTE
)stub
, &size
);
930 /* launch the user stub wrapper */
931 hr
= launch_exe(stub
, NULL
, NULL
);
940 /***********************************************************************
941 * UserUnInstStubWrapperA (ADVPACK.@)
943 * See UserUnInstStubWrapperW.
945 HRESULT WINAPI
UserUnInstStubWrapperA(HWND hWnd
, HINSTANCE hInstance
,
946 LPSTR pszParms
, INT nShow
)
948 UNICODE_STRING parmsW
;
951 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInstance
, debugstr_a(pszParms
), nShow
);
956 RtlCreateUnicodeStringFromAsciiz(&parmsW
, pszParms
);
958 res
= UserUnInstStubWrapperW(hWnd
, hInstance
, parmsW
.Buffer
, nShow
);
960 RtlFreeUnicodeString(&parmsW
);
965 /***********************************************************************
966 * UserUnInstStubWrapperW (ADVPACK.@)
968 HRESULT WINAPI
UserUnInstStubWrapperW(HWND hWnd
, HINSTANCE hInstance
,
969 LPWSTR pszParms
, INT nShow
)
971 FIXME("(%p, %p, %s, %i): stub\n", hWnd
, hInstance
, debugstr_w(pszParms
), nShow
);