Fixed header dependencies to be fully compatible with the Windows
[wine/multimedia.git] / dlls / version / info.c
blob47302253fde3a61f8e2e6be8b0ec8e079d9d22e3
1 /*
2 * Implementation of VERSION.DLL - Version Info access
4 * Copyright 1996,1997 Marcus Meissner
5 * Copyright 1997 David Cuthbert
6 * Copyright 1999 Ulrich Weigand
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winreg.h"
30 #include "winver.h"
31 #include "wine/winuser16.h"
32 #include "wine/unicode.h"
33 #include "winerror.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ver);
39 /******************************************************************************
41 * This function will print via dprintf[_]ver to stddeb debug info regarding
42 * the file info structure vffi.
43 * 15-Feb-1998 Dimitrie Paun (dimi@cs.toronto.edu)
44 * Added this function to clean up the code.
46 *****************************************************************************/
47 static void print_vffi_debug(VS_FIXEDFILEINFO *vffi)
49 TRACE(" structversion=%u.%u, fileversion=%u.%u.%u.%u, productversion=%u.%u.%u.%u, flagmask=0x%lx, flags=%s%s%s%s%s%s\n",
50 HIWORD(vffi->dwStrucVersion),LOWORD(vffi->dwStrucVersion),
51 HIWORD(vffi->dwFileVersionMS),LOWORD(vffi->dwFileVersionMS),
52 HIWORD(vffi->dwFileVersionLS),LOWORD(vffi->dwFileVersionLS),
53 HIWORD(vffi->dwProductVersionMS),LOWORD(vffi->dwProductVersionMS),
54 HIWORD(vffi->dwProductVersionLS),LOWORD(vffi->dwProductVersionLS),
55 vffi->dwFileFlagsMask,
56 (vffi->dwFileFlags & VS_FF_DEBUG) ? "DEBUG," : "",
57 (vffi->dwFileFlags & VS_FF_PRERELEASE) ? "PRERELEASE," : "",
58 (vffi->dwFileFlags & VS_FF_PATCHED) ? "PATCHED," : "",
59 (vffi->dwFileFlags & VS_FF_PRIVATEBUILD) ? "PRIVATEBUILD," : "",
60 (vffi->dwFileFlags & VS_FF_INFOINFERRED) ? "INFOINFERRED," : "",
61 (vffi->dwFileFlags & VS_FF_SPECIALBUILD) ? "SPECIALBUILD," : ""
64 TRACE("(");
65 TRACE(" OS=0x%x.0x%x ",
66 HIWORD(vffi->dwFileOS),
67 LOWORD(vffi->dwFileOS)
69 switch (vffi->dwFileOS&0xFFFF0000) {
70 case VOS_DOS:TRACE("DOS,");break;
71 case VOS_OS216:TRACE("OS/2-16,");break;
72 case VOS_OS232:TRACE("OS/2-32,");break;
73 case VOS_NT:TRACE("NT,");break;
74 case VOS_UNKNOWN:
75 default:
76 TRACE("UNKNOWN(0x%lx),",vffi->dwFileOS&0xFFFF0000);break;
78 switch (LOWORD(vffi->dwFileOS)) {
79 case VOS__BASE:TRACE("BASE");break;
80 case VOS__WINDOWS16:TRACE("WIN16");break;
81 case VOS__WINDOWS32:TRACE("WIN32");break;
82 case VOS__PM16:TRACE("PM16");break;
83 case VOS__PM32:TRACE("PM32");break;
84 default:TRACE("UNKNOWN(0x%x)",LOWORD(vffi->dwFileOS));break;
86 TRACE(")\n");
88 switch (vffi->dwFileType) {
89 default:
90 case VFT_UNKNOWN:
91 TRACE("filetype=Unknown(0x%lx)",vffi->dwFileType);
92 break;
93 case VFT_APP:TRACE("filetype=APP,");break;
94 case VFT_DLL:TRACE("filetype=DLL,");break;
95 case VFT_DRV:
96 TRACE("filetype=DRV,");
97 switch(vffi->dwFileSubtype) {
98 default:
99 case VFT2_UNKNOWN:
100 TRACE("UNKNOWN(0x%lx)",vffi->dwFileSubtype);
101 break;
102 case VFT2_DRV_PRINTER:
103 TRACE("PRINTER");
104 break;
105 case VFT2_DRV_KEYBOARD:
106 TRACE("KEYBOARD");
107 break;
108 case VFT2_DRV_LANGUAGE:
109 TRACE("LANGUAGE");
110 break;
111 case VFT2_DRV_DISPLAY:
112 TRACE("DISPLAY");
113 break;
114 case VFT2_DRV_MOUSE:
115 TRACE("MOUSE");
116 break;
117 case VFT2_DRV_NETWORK:
118 TRACE("NETWORK");
119 break;
120 case VFT2_DRV_SYSTEM:
121 TRACE("SYSTEM");
122 break;
123 case VFT2_DRV_INSTALLABLE:
124 TRACE("INSTALLABLE");
125 break;
126 case VFT2_DRV_SOUND:
127 TRACE("SOUND");
128 break;
129 case VFT2_DRV_COMM:
130 TRACE("COMM");
131 break;
132 case VFT2_DRV_INPUTMETHOD:
133 TRACE("INPUTMETHOD");
134 break;
136 break;
137 case VFT_FONT:
138 TRACE("filetype=FONT.");
139 switch (vffi->dwFileSubtype) {
140 default:
141 TRACE("UNKNOWN(0x%lx)",vffi->dwFileSubtype);
142 break;
143 case VFT2_FONT_RASTER:TRACE("RASTER");break;
144 case VFT2_FONT_VECTOR:TRACE("VECTOR");break;
145 case VFT2_FONT_TRUETYPE:TRACE("TRUETYPE");break;
147 break;
148 case VFT_VXD:TRACE("filetype=VXD");break;
149 case VFT_STATIC_LIB:TRACE("filetype=STATIC_LIB");break;
151 TRACE("\n");
152 TRACE(" filedata=0x%lx.0x%lx\n",
153 vffi->dwFileDateMS,vffi->dwFileDateLS);
157 /***********************************************************************
158 * Version Info Structure
161 typedef struct
163 WORD wLength;
164 WORD wValueLength;
165 CHAR szKey[1];
166 #if 0 /* variable length structure */
167 /* DWORD aligned */
168 BYTE Value[];
169 /* DWORD aligned */
170 VS_VERSION_INFO_STRUCT16 Children[];
171 #endif
172 } VS_VERSION_INFO_STRUCT16;
174 typedef struct
176 WORD wLength;
177 WORD wValueLength;
178 WORD bText;
179 WCHAR szKey[1];
180 #if 0 /* variable length structure */
181 /* DWORD aligned */
182 BYTE Value[];
183 /* DWORD aligned */
184 VS_VERSION_INFO_STRUCT32 Children[];
185 #endif
186 } VS_VERSION_INFO_STRUCT32;
188 #define VersionInfoIs16( ver ) \
189 ( ((VS_VERSION_INFO_STRUCT16 *)ver)->szKey[0] >= ' ' )
191 #define DWORD_ALIGN( base, ptr ) \
192 ( (LPBYTE)(base) + ((((LPBYTE)(ptr) - (LPBYTE)(base)) + 3) & ~3) )
194 #define VersionInfo16_Value( ver ) \
195 DWORD_ALIGN( (ver), (ver)->szKey + strlen((ver)->szKey) + 1 )
196 #define VersionInfo32_Value( ver ) \
197 DWORD_ALIGN( (ver), (ver)->szKey + strlenW((ver)->szKey) + 1 )
199 #define VersionInfo16_Children( ver ) \
200 (VS_VERSION_INFO_STRUCT16 *)( VersionInfo16_Value( ver ) + \
201 ( ( (ver)->wValueLength + 3 ) & ~3 ) )
202 #define VersionInfo32_Children( ver ) \
203 (VS_VERSION_INFO_STRUCT32 *)( VersionInfo32_Value( ver ) + \
204 ( ( (ver)->wValueLength * \
205 ((ver)->bText? 2 : 1) + 3 ) & ~3 ) )
207 #define VersionInfo16_Next( ver ) \
208 (VS_VERSION_INFO_STRUCT16 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
209 #define VersionInfo32_Next( ver ) \
210 (VS_VERSION_INFO_STRUCT32 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
212 /***********************************************************************
213 * ConvertVersionInfo32To16 [internal]
215 void ConvertVersionInfo32To16( VS_VERSION_INFO_STRUCT32 *info32,
216 VS_VERSION_INFO_STRUCT16 *info16 )
218 /* Copy data onto local stack to prevent overwrites */
219 WORD wLength = info32->wLength;
220 WORD wValueLength = info32->wValueLength;
221 WORD bText = info32->bText;
222 LPBYTE lpValue = VersionInfo32_Value( info32 );
223 VS_VERSION_INFO_STRUCT32 *child32 = VersionInfo32_Children( info32 );
224 VS_VERSION_INFO_STRUCT16 *child16;
226 TRACE("Converting %p to %p\n", info32, info16 );
227 TRACE("wLength %d, wValueLength %d, bText %d, value %p, child %p\n",
228 wLength, wValueLength, bText, lpValue, child32 );
230 /* Convert key */
231 WideCharToMultiByte( CP_ACP, 0, info32->szKey, -1, info16->szKey, 0x7fffffff, NULL, NULL );
233 TRACE("Copied key from %p to %p: %s\n", info32->szKey, info16->szKey,
234 debugstr_a(info16->szKey) );
236 /* Convert value */
237 if ( wValueLength == 0 )
239 info16->wValueLength = 0;
240 TRACE("No value present\n" );
242 else if ( bText )
244 info16->wValueLength = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)lpValue, -1, NULL, 0, NULL, NULL );
245 WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)lpValue, -1,
246 VersionInfo16_Value( info16 ), info16->wValueLength, NULL, NULL );
248 TRACE("Copied value from %p to %p: %s\n", lpValue,
249 VersionInfo16_Value( info16 ),
250 debugstr_a(VersionInfo16_Value( info16 )) );
252 else
254 info16->wValueLength = wValueLength;
255 memmove( VersionInfo16_Value( info16 ), lpValue, wValueLength );
257 TRACE("Copied value from %p to %p: %d bytes\n", lpValue,
258 VersionInfo16_Value( info16 ), wValueLength );
261 /* Convert children */
262 child16 = VersionInfo16_Children( info16 );
263 while ( (DWORD)child32 < (DWORD)info32 + wLength && child32->wLength != 0 )
265 VS_VERSION_INFO_STRUCT32 *nextChild = VersionInfo32_Next( child32 );
267 ConvertVersionInfo32To16( child32, child16 );
269 child16 = VersionInfo16_Next( child16 );
270 child32 = nextChild;
273 /* Fixup length */
274 info16->wLength = (DWORD)child16 - (DWORD)info16;
276 TRACE("Finished, length is %d (%p - %p)\n",
277 info16->wLength, info16, child16 );
280 /***********************************************************************
281 * VERSION_GetFileVersionInfo_PE [internal]
283 * NOTE: returns size of the PE VERSION resource or 0xFFFFFFFF
284 * in the case if file exists, but VERSION_INFO not found.
285 * FIXME: handle is not used.
287 static DWORD VERSION_GetFileVersionInfo_PE( LPCSTR filename, LPDWORD handle,
288 DWORD datasize, LPVOID data )
290 VS_FIXEDFILEINFO *vffi;
291 DWORD len;
292 BYTE *buf;
293 HMODULE hModule;
294 HRSRC hRsrc;
295 HGLOBAL hMem;
297 TRACE("(%s,%p)\n", debugstr_a(filename), handle );
299 hModule = GetModuleHandleA(filename);
300 if(!hModule)
301 hModule = LoadLibraryExA(filename, 0, LOAD_LIBRARY_AS_DATAFILE);
302 else
303 hModule = LoadLibraryExA(filename, 0, 0);
304 if(!hModule)
306 WARN("Could not load %s\n", debugstr_a(filename));
307 return 0;
309 hRsrc = FindResourceW(hModule,
310 MAKEINTRESOURCEW(VS_VERSION_INFO),
311 MAKEINTRESOURCEW(VS_FILE_INFO));
312 if(!hRsrc)
314 WARN("Could not find VS_VERSION_INFO in %s\n", debugstr_a(filename));
315 FreeLibrary(hModule);
316 return 0xFFFFFFFF;
318 len = SizeofResource(hModule, hRsrc);
319 hMem = LoadResource(hModule, hRsrc);
320 if(!hMem)
322 WARN("Could not load VS_VERSION_INFO from %s\n", debugstr_a(filename));
323 FreeLibrary(hModule);
324 return 0xFFFFFFFF;
326 buf = LockResource(hMem);
328 vffi = (VS_FIXEDFILEINFO *)VersionInfo32_Value( (VS_VERSION_INFO_STRUCT32 *)buf );
330 if ( vffi->dwSignature != VS_FFI_SIGNATURE )
332 WARN("vffi->dwSignature is 0x%08lx, but not 0x%08lx!\n",
333 vffi->dwSignature, VS_FFI_SIGNATURE );
334 len = 0xFFFFFFFF;
335 goto END;
338 if ( TRACE_ON(ver) )
339 print_vffi_debug( vffi );
341 if(data)
343 if(datasize < len)
344 len = datasize; /* truncate data */
345 if(len)
346 memcpy(data, buf, len);
347 else
348 len = 0xFFFFFFFF;
350 END:
351 FreeResource(hMem);
352 FreeLibrary(hModule);
354 return len;
357 /***********************************************************************
358 * VERSION_GetFileVersionInfo_16 [internal]
360 * NOTE: returns size of the 16-bit VERSION resource or 0xFFFFFFFF
361 * in the case if file exists, but VERSION_INFO not found.
362 * FIXME: handle is not used.
364 static DWORD VERSION_GetFileVersionInfo_16( LPCSTR filename, LPDWORD handle,
365 DWORD datasize, LPVOID data )
367 VS_FIXEDFILEINFO *vffi;
368 DWORD len;
369 BYTE *buf;
370 HMODULE16 hModule;
371 HRSRC16 hRsrc;
372 HGLOBAL16 hMem;
374 TRACE("(%s,%p)\n", debugstr_a(filename), handle );
376 hModule = LoadLibrary16(filename);
377 if(hModule < 32)
379 WARN("Could not load %s\n", debugstr_a(filename));
380 return 0;
382 hRsrc = FindResource16(hModule,
383 MAKEINTRESOURCEA(VS_VERSION_INFO),
384 MAKEINTRESOURCEA(VS_FILE_INFO));
385 if(!hRsrc)
387 WARN("Could not find VS_VERSION_INFO in %s\n", debugstr_a(filename));
388 FreeLibrary16(hModule);
389 return 0xFFFFFFFF;
391 len = SizeofResource16(hModule, hRsrc);
392 hMem = LoadResource16(hModule, hRsrc);
393 if(!hMem)
395 WARN("Could not load VS_VERSION_INFO from %s\n", debugstr_a(filename));
396 FreeLibrary16(hModule);
397 return 0xFFFFFFFF;
399 buf = LockResource16(hMem);
401 if(!VersionInfoIs16(buf))
402 goto END;
404 vffi = (VS_FIXEDFILEINFO *)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16 *)buf );
406 if ( vffi->dwSignature != VS_FFI_SIGNATURE )
408 WARN("vffi->dwSignature is 0x%08lx, but not 0x%08lx!\n",
409 vffi->dwSignature, VS_FFI_SIGNATURE );
410 len = 0xFFFFFFFF;
411 goto END;
414 if ( TRACE_ON(ver) )
415 print_vffi_debug( vffi );
417 if(data)
419 if(datasize < len)
420 len = datasize; /* truncate data */
421 if(len)
422 memcpy(data, buf, len);
423 else
424 len = 0xFFFFFFFF;
426 END:
427 FreeResource16(hMem);
428 FreeLibrary16(hModule);
430 return len;
433 /***********************************************************************
434 * GetFileVersionInfoSizeA [VERSION.@]
436 DWORD WINAPI GetFileVersionInfoSizeA( LPCSTR filename, LPDWORD handle )
438 VS_FIXEDFILEINFO *vffi;
439 DWORD len, ret, offset;
440 BYTE buf[144];
442 TRACE("(%s,%p)\n", debugstr_a(filename), handle );
444 len = VERSION_GetFileVersionInfo_PE(filename, handle, 0, NULL);
445 /* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
446 if(len == 0xFFFFFFFF)
448 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
449 return 0;
451 if(len) return len;
452 len = VERSION_GetFileVersionInfo_16(filename, handle, 0, NULL);
453 /* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
454 if(len == 0xFFFFFFFF)
456 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
457 return 0;
459 if(len) return len;
461 len = GetFileResourceSize16( filename,
462 MAKEINTRESOURCEA(VS_FILE_INFO),
463 MAKEINTRESOURCEA(VS_VERSION_INFO),
464 &offset );
465 if (!len) return 0;
467 ret = GetFileResource16( filename,
468 MAKEINTRESOURCEA(VS_FILE_INFO),
469 MAKEINTRESOURCEA(VS_VERSION_INFO),
470 offset, sizeof( buf ), buf );
471 if (!ret) return 0;
473 if ( handle ) *handle = offset;
475 if ( VersionInfoIs16( buf ) )
476 vffi = (VS_FIXEDFILEINFO *)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16 *)buf );
477 else
478 vffi = (VS_FIXEDFILEINFO *)VersionInfo32_Value( (VS_VERSION_INFO_STRUCT32 *)buf );
480 if ( vffi->dwSignature != VS_FFI_SIGNATURE )
482 WARN("vffi->dwSignature is 0x%08lx, but not 0x%08lx!\n",
483 vffi->dwSignature, VS_FFI_SIGNATURE );
484 return 0;
487 if ( ((VS_VERSION_INFO_STRUCT16 *)buf)->wLength < len )
488 len = ((VS_VERSION_INFO_STRUCT16 *)buf)->wLength;
490 if ( TRACE_ON(ver) )
491 print_vffi_debug( vffi );
493 return len;
496 /***********************************************************************
497 * GetFileVersionInfoSizeW [VERSION.@]
499 DWORD WINAPI GetFileVersionInfoSizeW( LPCWSTR filename, LPDWORD handle )
501 DWORD ret, len = WideCharToMultiByte( CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL );
502 LPSTR fn = HeapAlloc( GetProcessHeap(), 0, len );
503 WideCharToMultiByte( CP_ACP, 0, filename, -1, fn, len, NULL, NULL );
504 ret = GetFileVersionInfoSizeA( fn, handle );
505 HeapFree( GetProcessHeap(), 0, fn );
506 return ret;
509 /***********************************************************************
510 * GetFileVersionInfoA [VERSION.@]
512 BOOL WINAPI GetFileVersionInfoA( LPCSTR filename, DWORD handle,
513 DWORD datasize, LPVOID data )
515 DWORD len;
517 TRACE("(%s,%ld,size=%ld,data=%p)\n",
518 debugstr_a(filename), handle, datasize, data );
520 len = VERSION_GetFileVersionInfo_PE(filename, &handle, datasize, data);
521 /* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
522 if(len == 0xFFFFFFFF) return FALSE;
523 if(len)
524 goto DO_CONVERT;
525 len = VERSION_GetFileVersionInfo_16(filename, &handle, datasize, data);
526 /* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
527 if(len == 0xFFFFFFFF) return FALSE;
528 if(len)
529 goto DO_CONVERT;
531 if ( !GetFileResource16( filename, MAKEINTRESOURCEA(VS_FILE_INFO),
532 MAKEINTRESOURCEA(VS_VERSION_INFO),
533 handle, datasize, data ) )
534 return FALSE;
535 DO_CONVERT:
536 if ( datasize >= sizeof(VS_VERSION_INFO_STRUCT16)
537 && datasize >= ((VS_VERSION_INFO_STRUCT16 *)data)->wLength
538 && !VersionInfoIs16( data ) )
540 /* convert resource from PE format to NE format */
541 ConvertVersionInfo32To16( (VS_VERSION_INFO_STRUCT32 *)data,
542 (VS_VERSION_INFO_STRUCT16 *)data );
545 return TRUE;
548 /***********************************************************************
549 * GetFileVersionInfoW [VERSION.@]
551 BOOL WINAPI GetFileVersionInfoW( LPCWSTR filename, DWORD handle,
552 DWORD datasize, LPVOID data )
554 DWORD len = WideCharToMultiByte( CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL );
555 LPSTR fn = HeapAlloc( GetProcessHeap(), 0, len );
556 DWORD retv = TRUE;
558 WideCharToMultiByte( CP_ACP, 0, filename, -1, fn, len, NULL, NULL );
560 TRACE("(%s,%ld,size=%ld,data=%p)\n",
561 debugstr_w(filename), handle, datasize, data );
563 if(VERSION_GetFileVersionInfo_PE(fn, &handle, datasize, data))
564 goto END;
565 if(VERSION_GetFileVersionInfo_16(fn, &handle, datasize, data))
566 goto END;
568 if ( !GetFileResource16( fn, MAKEINTRESOURCEA(VS_FILE_INFO),
569 MAKEINTRESOURCEA(VS_VERSION_INFO),
570 handle, datasize, data ) )
571 retv = FALSE;
573 else if ( datasize >= sizeof(VS_VERSION_INFO_STRUCT16)
574 && datasize >= ((VS_VERSION_INFO_STRUCT16 *)data)->wLength
575 && VersionInfoIs16( data ) )
577 ERR("Cannot access NE resource in %s\n", debugstr_a(fn) );
578 retv = FALSE;
580 END:
581 HeapFree( GetProcessHeap(), 0, fn );
582 return retv;
586 /***********************************************************************
587 * VersionInfo16_FindChild [internal]
589 static VS_VERSION_INFO_STRUCT16 *VersionInfo16_FindChild( VS_VERSION_INFO_STRUCT16 *info,
590 LPCSTR szKey, UINT cbKey )
592 VS_VERSION_INFO_STRUCT16 *child = VersionInfo16_Children( info );
594 while ( (DWORD)child < (DWORD)info + info->wLength )
596 if ( !strncasecmp( child->szKey, szKey, cbKey ) )
597 return child;
599 if (!(child->wLength)) return NULL;
600 child = VersionInfo16_Next( child );
603 return NULL;
606 /***********************************************************************
607 * VersionInfo32_FindChild [internal]
609 static VS_VERSION_INFO_STRUCT32 *VersionInfo32_FindChild( VS_VERSION_INFO_STRUCT32 *info,
610 LPCWSTR szKey, UINT cbKey )
612 VS_VERSION_INFO_STRUCT32 *child = VersionInfo32_Children( info );
614 while ( (DWORD)child < (DWORD)info + info->wLength )
616 if ( !strncmpiW( child->szKey, szKey, cbKey ) )
617 return child;
619 child = VersionInfo32_Next( child );
622 return NULL;
625 /***********************************************************************
626 * VerQueryValueA [VERSION.@]
628 DWORD WINAPI VerQueryValueA( LPVOID pBlock, LPCSTR lpSubBlock,
629 LPVOID *lplpBuffer, UINT *puLen )
631 VS_VERSION_INFO_STRUCT16 *info = (VS_VERSION_INFO_STRUCT16 *)pBlock;
632 if ( !VersionInfoIs16( info ) )
634 INT len;
635 LPWSTR wide_str;
636 DWORD give;
638 /* <lawson_whitney@juno.com> Feb 2001 */
639 /* AOL 5.0 does this, expecting to get this: */
640 len = MultiByteToWideChar(CP_ACP, 0, lpSubBlock, -1, NULL, 0);
641 wide_str = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
642 MultiByteToWideChar(CP_ACP, 0, lpSubBlock, -1, wide_str, len);
644 give = VerQueryValueW(pBlock, wide_str, lplpBuffer, puLen);
645 HeapFree(GetProcessHeap(), 0, wide_str);
646 return give;
649 TRACE("(%p,%s,%p,%p)\n",
650 pBlock, debugstr_a(lpSubBlock), lplpBuffer, puLen );
652 while ( *lpSubBlock )
654 /* Find next path component */
655 LPCSTR lpNextSlash;
656 for ( lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++ )
657 if ( *lpNextSlash == '\\' )
658 break;
660 /* Skip empty components */
661 if ( lpNextSlash == lpSubBlock )
663 lpSubBlock++;
664 continue;
667 /* We have a non-empty component: search info for key */
668 info = VersionInfo16_FindChild( info, lpSubBlock, lpNextSlash-lpSubBlock );
669 if ( !info ) return FALSE;
671 /* Skip path component */
672 lpSubBlock = lpNextSlash;
675 /* Return value */
676 *lplpBuffer = VersionInfo16_Value( info );
677 *puLen = info->wValueLength;
679 return TRUE;
682 /***********************************************************************
683 * VerQueryValueW [VERSION.@]
685 DWORD WINAPI VerQueryValueW( LPVOID pBlock, LPCWSTR lpSubBlock,
686 LPVOID *lplpBuffer, UINT *puLen )
688 VS_VERSION_INFO_STRUCT32 *info = (VS_VERSION_INFO_STRUCT32 *)pBlock;
689 if ( VersionInfoIs16( info ) )
691 ERR("called on NE resource!\n" );
692 return FALSE;
695 TRACE("(%p,%s,%p,%p)\n",
696 pBlock, debugstr_w(lpSubBlock), lplpBuffer, puLen );
698 while ( *lpSubBlock )
700 /* Find next path component */
701 LPCWSTR lpNextSlash;
702 for ( lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++ )
703 if ( *lpNextSlash == '\\' )
704 break;
706 /* Skip empty components */
707 if ( lpNextSlash == lpSubBlock )
709 lpSubBlock++;
710 continue;
713 /* We have a non-empty component: search info for key */
714 info = VersionInfo32_FindChild( info, lpSubBlock, lpNextSlash-lpSubBlock );
715 if ( !info ) return FALSE;
717 /* Skip path component */
718 lpSubBlock = lpNextSlash;
721 /* Return value */
722 *lplpBuffer = VersionInfo32_Value( info );
723 *puLen = info->wValueLength;
725 return TRUE;