Format VT_UI1, VT_I1, VT_UI2, VT_I2 correctly.
[wine] / dlls / advpack / advpack.c
1 /*
2  * Advpack main
3  *
4  * Copyright 2004 Huw D M Davies
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "winreg.h"
27 #include "winver.h"
28 #include "winnls.h"
29 #include "setupapi.h"
30 #include "advpub.h"
31 #include "wine/unicode.h"
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(advpack);
35
36 typedef HRESULT (WINAPI *DLLREGISTER) (void);
37
38
39 /***********************************************************************
40  *           DllMain (ADVPACK.@)
41  */
42 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
43 {
44     TRACE("(%p, %ld, %p)\n",hinstDLL, fdwReason, lpvReserved);
45
46     if (fdwReason == DLL_PROCESS_ATTACH)
47         DisableThreadLibraryCalls(hinstDLL);
48
49     return TRUE;
50 }
51
52 /***********************************************************************
53  *              LaunchINFSection  (ADVPACK.@)
54  */
55 void WINAPI LaunchINFSection( HWND hWnd, HINSTANCE hInst, LPCSTR cmdline, INT show )
56 {
57     FIXME("%p %p %s %d\n", hWnd, hInst, debugstr_a(cmdline), show );
58 }
59
60 /***********************************************************************
61  *              LaunchINFSectionEx  (ADVPACK.@)
62  */
63 void WINAPI LaunchINFSectionEx( HWND hWnd, HINSTANCE hInst, LPCSTR cmdline, INT show )
64 {
65     FIXME("%p %p %s %d\n", hWnd, hInst, debugstr_a(cmdline), show );
66 }
67
68 /* this structure very closely resembles parameters of RunSetupCommand() */
69 typedef struct
70 {
71     HWND hwnd;
72     LPCSTR title;
73     LPCSTR inf_name;
74     LPCSTR dir;
75     LPCSTR section_name;
76 } SETUPCOMMAND_PARAMS;
77
78 /***********************************************************************
79  *              DoInfInstall  (ADVPACK.@)
80  */
81 BOOL WINAPI DoInfInstall(const SETUPCOMMAND_PARAMS *setup)
82 {
83     BOOL ret;
84     HINF hinf;
85     void *callback_context;
86
87     TRACE("%p %s %s %s %s\n", setup->hwnd, debugstr_a(setup->title),
88           debugstr_a(setup->inf_name), debugstr_a(setup->dir),
89           debugstr_a(setup->section_name));
90
91     hinf = SetupOpenInfFileA(setup->inf_name, NULL, INF_STYLE_WIN4, NULL);
92     if (hinf == INVALID_HANDLE_VALUE) return FALSE;
93
94     callback_context = SetupInitDefaultQueueCallback(setup->hwnd);
95
96     ret = SetupInstallFromInfSectionA(NULL, hinf, setup->section_name, SPINST_ALL,
97                                       NULL, NULL, 0, SetupDefaultQueueCallbackA,
98                                       callback_context, NULL, NULL);
99     SetupTermDefaultQueueCallback(callback_context);
100     SetupCloseInfFile(hinf);
101
102     return ret;
103 }
104
105 /***********************************************************************
106  *             NeedRebootInit  (ADVPACK.@)
107  */
108 DWORD WINAPI NeedRebootInit(VOID)
109 {
110     FIXME("() stub!\n");
111     return 0;
112 }
113
114 /***********************************************************************
115  *             NeedReboot      (ADVPACK.@)
116  */
117 BOOL WINAPI NeedReboot(DWORD dwRebootCheck)
118 {
119     FIXME("(0x%08lx) stub!\n", dwRebootCheck);
120     return FALSE;
121 }
122
123 /***********************************************************************
124  *             GetVersionFromFile      (ADVPACK.@)
125  */
126 HRESULT WINAPI GetVersionFromFile( LPSTR Filename, LPDWORD MajorVer,
127                                    LPDWORD MinorVer, BOOL Version )
128 {
129     TRACE("(%s, %p, %p, %d)\n", Filename, MajorVer, MinorVer, Version);
130     return GetVersionFromFileEx(Filename, MajorVer, MinorVer, Version);
131 }
132
133 /***********************************************************************
134  *             GetVersionFromFileEx    (ADVPACK.@)
135  */
136 HRESULT WINAPI GetVersionFromFileEx( LPSTR lpszFilename, LPDWORD pdwMSVer,
137                                      LPDWORD pdwLSVer, BOOL bVersion )
138 {
139     DWORD hdl, retval;
140     LPVOID pVersionInfo;
141     BOOL boolret;
142     VS_FIXEDFILEINFO *pFixedVersionInfo;
143     UINT uiLength;
144     TRACE("(%s, %p, %p, %d)\n", lpszFilename, pdwMSVer, pdwLSVer, bVersion);
145
146     if (bVersion)
147     {
148         retval = GetFileVersionInfoSizeA(lpszFilename, &hdl);
149         if (retval == 0 || hdl != 0)
150             return E_FAIL;
151
152         pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
153         if (pVersionInfo == NULL)
154              return E_FAIL;
155         GetFileVersionInfoA( lpszFilename, 0, retval, pVersionInfo);
156
157         boolret = VerQueryValueA(pVersionInfo, "\\",
158                                  (LPVOID) &pFixedVersionInfo, &uiLength);
159
160         HeapFree(GetProcessHeap(), 0, pVersionInfo);
161
162         if (boolret)
163         {
164             *pdwMSVer = pFixedVersionInfo->dwFileVersionMS;
165             *pdwLSVer = pFixedVersionInfo->dwFileVersionLS;
166         }
167         else
168             return E_FAIL;
169     }
170     else
171     {
172         *pdwMSVer = GetUserDefaultUILanguage();
173         *pdwLSVer = GetACP();
174     }
175
176     return S_OK;
177 }
178
179 /***********************************************************************
180  *             RegisterOCX    (ADVPACK.@)
181  */
182 void WINAPI RegisterOCX( HWND hWnd, HINSTANCE hInst, LPCSTR cmdline, INT show )
183 {
184     WCHAR wszBuff[MAX_PATH];
185     WCHAR* pwcComma;
186     HMODULE hm;
187     DLLREGISTER pfnRegister;
188     HRESULT hr;
189
190     TRACE("(%s)\n", cmdline);
191
192     MultiByteToWideChar(CP_ACP, 0, cmdline, strlen(cmdline), wszBuff, MAX_PATH);
193     if ((pwcComma = strchrW( wszBuff, ',' ))) *pwcComma = 0;
194
195     TRACE("Parsed DLL name (%s)\n", debugstr_w(wszBuff));
196
197     hm = LoadLibraryExW(wszBuff, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
198     if (!hm)
199     {
200         ERR("Couldn't load DLL: %s\n", debugstr_w(wszBuff));
201         return;
202     }
203
204     pfnRegister = (DLLREGISTER)GetProcAddress(hm, "DllRegisterServer");
205     if (pfnRegister == NULL)
206     {
207         ERR("DllRegisterServer entry point not found\n");
208     }
209     else
210     {
211         hr = pfnRegister();
212         if (hr != S_OK)
213         {
214             ERR("DllRegisterServer entry point returned %08lx\n", hr);
215         }
216     }
217
218     TRACE("Successfully registered OCX\n");
219
220     FreeLibrary(hm);
221 }
222
223 /***********************************************************************
224  *             DelNodeRunDLL32    (ADVPACK.@)
225  */
226 void WINAPI DelNodeRunDLL32( HWND hWnd, HINSTANCE hInst, LPCSTR cmdline, INT show )
227 {
228     FIXME("(%s) FIXME: stub\n", cmdline);
229 }