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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(advpack
);
37 typedef HRESULT (WINAPI
*DLLREGISTER
) (void);
39 /***********************************************************************
40 * CloseINFEngine (ADVPACK.@)
53 HRESULT WINAPI
CloseINFEngine(HINF hInf
)
55 FIXME("(%p) stub\n", hInf
);
60 /***********************************************************************
63 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
65 TRACE("(%p, %ld, %p)\n",hinstDLL
, fdwReason
, lpvReserved
);
67 if (fdwReason
== DLL_PROCESS_ATTACH
)
68 DisableThreadLibraryCalls(hinstDLL
);
73 /***********************************************************************
74 * RunSetupCommand (ADVPACK.@)
76 * Executes an install section in an INF file or a program.
79 * hWnd [I] Handle to parent window, NULL for quiet mode
80 * szCmdName [I] Inf or EXE filename to execute
81 * szInfSection [I] Inf section to install, NULL for DefaultInstall
82 * szDir [I] Path to extracted files
83 * szTitle [I] Title of all dialogs
84 * phEXE [O] Handle of EXE to wait for
85 * dwFlags [I] Flags; see include/advpub.h
86 * pvReserved [I] Reserved
90 * S_ASYNCHRONOUS OK, required to wait on phEXE
91 * ERROR_SUCCESS_REBOOT_REQUIRED Reboot required
92 * E_INVALIDARG Invalid argument given
93 * HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)
94 * Not supported on this Windows version
95 * E_UNEXPECTED Unexpected error
96 * HRESULT_FROM_WIN32(GetLastError()) Some other error
101 HRESULT WINAPI
RunSetupCommand( HWND hWnd
, LPCSTR szCmdName
,
102 LPCSTR szInfSection
, LPCSTR szDir
,
103 LPCSTR lpszTitle
, HANDLE
*phEXE
,
104 DWORD dwFlags
, LPVOID pvReserved
)
106 FIXME("(%p, %s, %s, %s, %s, %p, 0x%08lx, %p): stub\n",
107 hWnd
, debugstr_a(szCmdName
), debugstr_a(szInfSection
),
108 debugstr_a(szDir
), debugstr_a(lpszTitle
),
109 phEXE
, dwFlags
, pvReserved
);
113 /***********************************************************************
114 * LaunchINFSection (ADVPACK.@)
116 * Installs an INF section without BACKUP/ROLLBACK capabilities.
119 * hWnd [I] Handle to parent window, NULL for desktop.
120 * hInst [I] Instance of the process.
121 * cmdline [I] Contains parameters in the order INF,section,flags.
122 * show [I] Reboot behaviour:
124 * 'I' default, reboot if needed
134 INT WINAPI
LaunchINFSection( HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
136 FIXME("(%p %p %s %d): stub\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
140 /***********************************************************************
141 * LaunchINFSectionEx (ADVPACK.@)
143 * Installs an INF section with BACKUP/ROLLBACK capabilities.
146 * hWnd [I] Handle to parent window, NULL for desktop.
147 * hInst [I] Instance of the process.
148 * cmdline [I] Contains parameters in the order INF,section,CAB,flags.
149 * show [I] Reboot behaviour:
151 * 'I' default, reboot if needed
161 HRESULT WINAPI
LaunchINFSectionEx( HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
163 FIXME("(%p %p %s %d): stub\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
167 /* this structure very closely resembles parameters of RunSetupCommand() */
175 } SETUPCOMMAND_PARAMS
;
177 /***********************************************************************
178 * DoInfInstall (ADVPACK.@)
180 * Install an INF section.
183 * setup [I] Structure containing install information.
187 * HRESULT_FROM_WIN32(GetLastError()) Some other error
189 HRESULT WINAPI
DoInfInstall(const SETUPCOMMAND_PARAMS
*setup
)
193 void *callback_context
;
195 TRACE("%p %s %s %s %s\n", setup
->hwnd
, debugstr_a(setup
->title
),
196 debugstr_a(setup
->inf_name
), debugstr_a(setup
->dir
),
197 debugstr_a(setup
->section_name
));
199 hinf
= SetupOpenInfFileA(setup
->inf_name
, NULL
, INF_STYLE_WIN4
, NULL
);
200 if (hinf
== INVALID_HANDLE_VALUE
) return HRESULT_FROM_WIN32(GetLastError());
202 callback_context
= SetupInitDefaultQueueCallback(setup
->hwnd
);
204 ret
= SetupInstallFromInfSectionA(NULL
, hinf
, setup
->section_name
, SPINST_ALL
,
205 NULL
, NULL
, 0, SetupDefaultQueueCallbackA
,
206 callback_context
, NULL
, NULL
);
207 SetupTermDefaultQueueCallback(callback_context
);
208 SetupCloseInfFile(hinf
);
210 return ret
? S_OK
: HRESULT_FROM_WIN32(GetLastError());
213 /***********************************************************************
214 * IsNTAdmin (ADVPACK.@)
216 * Checks if the user has admin privileges.
219 * reserved [I] Reserved. Must be 0.
220 * pReserved [I] Reserved. Must be NULL.
223 * TRUE if user has admin rights, FALSE otherwise.
228 BOOL WINAPI
IsNTAdmin( DWORD reserved
, LPDWORD pReserved
)
230 FIXME("(0x%08lx, %p): stub\n", reserved
, pReserved
);
234 /***********************************************************************
235 * NeedRebootInit (ADVPACK.@)
237 * Sets up conditions for reboot checking.
240 * Value required by NeedReboot.
242 DWORD WINAPI
NeedRebootInit(VOID
)
248 /***********************************************************************
249 * NeedReboot (ADVPACK.@)
251 * Determines whether a reboot is required.
254 * dwRebootCheck [I] Value from NeedRebootInit.
257 * TRUE if a reboot is needed, FALSE otherwise.
262 BOOL WINAPI
NeedReboot(DWORD dwRebootCheck
)
264 FIXME("(0x%08lx): stub\n", dwRebootCheck
);
268 /***********************************************************************
269 * OpenINFEngine (ADVPACK.@)
271 * Opens and returns a handle to an INF file to be used by
272 * TranslateInfStringEx to continuously translate the INF file.
275 * pszInfFilename [I] Filename of the INF to open.
276 * pszInstallSection [I] Name of the Install section in the INF.
277 * dwFlags [I] See advpub.h.
278 * phInf [O] Handle to the loaded INF file.
279 * pvReserved [I] Reserved. Must be NULL.
288 HRESULT WINAPI
OpenINFEngine(PCSTR pszInfFilename
, PCSTR pszInstallSection
,
289 DWORD dwFlags
, HINF
*phInf
, PVOID pvReserved
)
291 FIXME("(%p, %p, %ld, %p, %p) stub\n", pszInfFilename
, pszInstallSection
,
292 dwFlags
, phInf
, pvReserved
);
297 /***********************************************************************
298 * RegisterOCX (ADVPACK.@)
300 void WINAPI
RegisterOCX( HWND hWnd
, HINSTANCE hInst
, LPCSTR cmdline
, INT show
)
302 WCHAR wszBuff
[MAX_PATH
];
305 DLLREGISTER pfnRegister
;
308 TRACE("(%s)\n", cmdline
);
310 MultiByteToWideChar(CP_ACP
, 0, cmdline
, strlen(cmdline
), wszBuff
, MAX_PATH
);
311 if ((pwcComma
= strchrW( wszBuff
, ',' ))) *pwcComma
= 0;
313 TRACE("Parsed DLL name (%s)\n", debugstr_w(wszBuff
));
315 hm
= LoadLibraryExW(wszBuff
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
318 ERR("Couldn't load DLL: %s\n", debugstr_w(wszBuff
));
322 pfnRegister
= (DLLREGISTER
)GetProcAddress(hm
, "DllRegisterServer");
323 if (pfnRegister
== NULL
)
325 ERR("DllRegisterServer entry point not found\n");
332 ERR("DllRegisterServer entry point returned %08lx\n", hr
);
336 TRACE("Successfully registered OCX\n");
341 /***********************************************************************
342 * ExecuteCab (ADVPACK.@)
344 * Installs the INF file extracted from a specified cabinet file.
347 * hwnd [I] Handle to the window used for the display.
348 * pCab [I] Information about the cabinet file.
349 * pReserved [I] Reserved. Must be NULL.
358 HRESULT WINAPI
ExecuteCab( HWND hwnd
, PCABINFO pCab
, LPVOID pReserved
)
360 FIXME("(%p %p %p): stub\n", hwnd
, pCab
, pReserved
);
364 /***********************************************************************
365 * TranslateInfString (ADVPACK.@)
367 * Translates the value of a specified key in an inf file into the
368 * current locale by expanding string macros.
371 * pszInfFilename [I] Filename of the inf file.
372 * pszInstallSection [I]
373 * pszTranslateSection [I] Inf section where the key exists.
374 * pszTranslateKey [I] Key to translate.
375 * pszBuffer [O] Contains the translated string on exit.
376 * dwBufferSize [I] Size on input of pszBuffer.
377 * pdwRequiredSize [O] Length of the translated key.
378 * pvReserved [I] Reserved, must be NULL.
382 * Failure: An hresult error code.
384 HRESULT WINAPI
TranslateInfString(PCSTR pszInfFilename
, PCSTR pszInstallSection
,
385 PCSTR pszTranslateSection
, PCSTR pszTranslateKey
, PSTR pszBuffer
,
386 DWORD dwBufferSize
, PDWORD pdwRequiredSize
, PVOID pvReserved
)
390 TRACE("(%s %s %s %s %p %ld %p %p)\n",
391 debugstr_a(pszInfFilename
), debugstr_a(pszInstallSection
),
392 debugstr_a(pszTranslateSection
), debugstr_a(pszTranslateKey
),
393 pszBuffer
, dwBufferSize
,pdwRequiredSize
, pvReserved
);
395 if (!pszInfFilename
|| !pszTranslateSection
||
396 !pszTranslateKey
|| !pdwRequiredSize
)
399 hInf
= SetupOpenInfFileA(pszInfFilename
, NULL
, INF_STYLE_WIN4
, NULL
);
400 if (hInf
== INVALID_HANDLE_VALUE
)
401 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
403 if (!SetupGetLineTextA(NULL
, hInf
, pszTranslateSection
, pszTranslateKey
,
404 pszBuffer
, dwBufferSize
, pdwRequiredSize
))
406 if (dwBufferSize
< *pdwRequiredSize
)
407 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
409 return SPAPI_E_LINE_NOT_FOUND
;
415 /***********************************************************************
416 * TranslateInfStringEx (ADVPACK.@)
418 * Using a handle to an INF file opened with OpenINFEngine, translates
419 * the value of a specified key in an inf file into the current locale
420 * by expanding string macros.
423 * hInf [I] Handle to the INF file.
424 * pszInfFilename [I] Filename of the INF file.
425 * pszTranslateSection [I] Inf section where the key exists.
426 * pszTranslateKey [I] Key to translate.
427 * pszBuffer [O] Contains the translated string on exit.
428 * dwBufferSize [I] Size on input of pszBuffer.
429 * pdwRequiredSize [O] Length of the translated key.
430 * pvReserved [I] Reserved. Must be NULL.
437 * To use TranslateInfStringEx to translate an INF file continuously,
438 * open the INF file with OpenINFEngine, call TranslateInfStringEx as
439 * many times as needed, then release the handle with CloseINFEngine.
440 * When translating more than one keys, this method is more efficient
441 * than calling TranslateInfString, because the INF file is only
447 HRESULT WINAPI
TranslateInfStringEx(HINF hInf
, PCSTR pszInfFilename
,
448 PCSTR pszTranslateSection
, PCSTR pszTranslateKey
,
449 PSTR pszBuffer
, DWORD dwBufferSize
,
450 PDWORD pdwRequiredSize
, PVOID pvReserved
)
452 FIXME("(%p, %p, %p, %p, %p, %ld, %p, %p) stub\n", hInf
, pszInfFilename
,
453 pszTranslateSection
, pszTranslateKey
, pszBuffer
, dwBufferSize
,
454 pdwRequiredSize
, pvReserved
);