2 * Implementation of VERSION.DLL - Version Info access
4 * Copyright 1996,1997 Marcus Meissner
5 * Copyright 1997 David Cuthbert
6 * Copyright 1999 Ulrich Weigand
7 * Copyright 2005 Paul Vriens
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/winuser16.h"
34 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ver
);
40 /******************************************************************************
42 * This function will print via standard TRACE, debug info regarding
43 * the file info structure vffi.
44 * 15-Feb-1998 Dimitrie Paun (dimi@cs.toronto.edu)
45 * Added this function to clean up the code.
47 *****************************************************************************/
48 static void print_vffi_debug(const VS_FIXEDFILEINFO
*vffi
)
50 BOOL versioned_printer
= FALSE
;
52 if((vffi
->dwFileType
== VFT_DLL
) || (vffi
->dwFileType
== VFT_DRV
))
54 if(vffi
->dwFileSubtype
== VFT2_DRV_VERSIONED_PRINTER
)
55 /* this is documented for newer w2k Drivers and up */
56 versioned_printer
= TRUE
;
57 else if( (vffi
->dwFileSubtype
== VFT2_DRV_PRINTER
) &&
58 (vffi
->dwFileVersionMS
!= vffi
->dwProductVersionMS
) &&
59 (vffi
->dwFileVersionMS
> 0) &&
60 (vffi
->dwFileVersionMS
<= 3) )
61 /* found this on NT 3.51, NT4.0 and old w2k Drivers */
62 versioned_printer
= TRUE
;
65 TRACE("structversion=%u.%u, ",
66 HIWORD(vffi
->dwStrucVersion
),LOWORD(vffi
->dwStrucVersion
));
69 WORD mode
= LOWORD(vffi
->dwFileVersionMS
);
70 WORD ver_rev
= HIWORD(vffi
->dwFileVersionLS
);
71 TRACE("fileversion=%u.%u.%u.%u (%s.major.minor.release), ",
72 (vffi
->dwFileVersionMS
),
73 HIBYTE(ver_rev
), LOBYTE(ver_rev
), LOWORD(vffi
->dwFileVersionLS
),
74 (mode
== 3) ? "Usermode" : ((mode
<= 2) ? "Kernelmode" : "?") );
78 TRACE("fileversion=%u.%u.%u.%u, ",
79 HIWORD(vffi
->dwFileVersionMS
),LOWORD(vffi
->dwFileVersionMS
),
80 HIWORD(vffi
->dwFileVersionLS
),LOWORD(vffi
->dwFileVersionLS
));
82 TRACE("productversion=%u.%u.%u.%u\n",
83 HIWORD(vffi
->dwProductVersionMS
),LOWORD(vffi
->dwProductVersionMS
),
84 HIWORD(vffi
->dwProductVersionLS
),LOWORD(vffi
->dwProductVersionLS
));
86 TRACE("flagmask=0x%x, flags=0x%x %s%s%s%s%s%s\n",
87 vffi
->dwFileFlagsMask
, vffi
->dwFileFlags
,
88 (vffi
->dwFileFlags
& VS_FF_DEBUG
) ? "DEBUG," : "",
89 (vffi
->dwFileFlags
& VS_FF_PRERELEASE
) ? "PRERELEASE," : "",
90 (vffi
->dwFileFlags
& VS_FF_PATCHED
) ? "PATCHED," : "",
91 (vffi
->dwFileFlags
& VS_FF_PRIVATEBUILD
) ? "PRIVATEBUILD," : "",
92 (vffi
->dwFileFlags
& VS_FF_INFOINFERRED
) ? "INFOINFERRED," : "",
93 (vffi
->dwFileFlags
& VS_FF_SPECIALBUILD
) ? "SPECIALBUILD," : "");
97 TRACE("OS=0x%x.0x%x ", HIWORD(vffi
->dwFileOS
), LOWORD(vffi
->dwFileOS
));
99 switch (vffi
->dwFileOS
&0xFFFF0000)
101 case VOS_DOS
:TRACE("DOS,");break;
102 case VOS_OS216
:TRACE("OS/2-16,");break;
103 case VOS_OS232
:TRACE("OS/2-32,");break;
104 case VOS_NT
:TRACE("NT,");break;
107 TRACE("UNKNOWN(0x%x),",vffi
->dwFileOS
&0xFFFF0000);break;
110 switch (LOWORD(vffi
->dwFileOS
))
112 case VOS__BASE
:TRACE("BASE");break;
113 case VOS__WINDOWS16
:TRACE("WIN16");break;
114 case VOS__WINDOWS32
:TRACE("WIN32");break;
115 case VOS__PM16
:TRACE("PM16");break;
116 case VOS__PM32
:TRACE("PM32");break;
118 TRACE("UNKNOWN(0x%x)",LOWORD(vffi
->dwFileOS
));break;
123 switch (vffi
->dwFileType
)
125 case VFT_APP
:TRACE("filetype=APP");break;
127 TRACE("filetype=DLL");
128 if(vffi
->dwFileSubtype
!= 0)
130 if(versioned_printer
) /* NT3.x/NT4.0 or old w2k Driver */
132 TRACE(" (subtype=0x%x)", vffi
->dwFileSubtype
);
136 TRACE("filetype=DRV,");
137 switch(vffi
->dwFileSubtype
)
139 case VFT2_DRV_PRINTER
:TRACE("PRINTER");break;
140 case VFT2_DRV_KEYBOARD
:TRACE("KEYBOARD");break;
141 case VFT2_DRV_LANGUAGE
:TRACE("LANGUAGE");break;
142 case VFT2_DRV_DISPLAY
:TRACE("DISPLAY");break;
143 case VFT2_DRV_MOUSE
:TRACE("MOUSE");break;
144 case VFT2_DRV_NETWORK
:TRACE("NETWORK");break;
145 case VFT2_DRV_SYSTEM
:TRACE("SYSTEM");break;
146 case VFT2_DRV_INSTALLABLE
:TRACE("INSTALLABLE");break;
147 case VFT2_DRV_SOUND
:TRACE("SOUND");break;
148 case VFT2_DRV_COMM
:TRACE("COMM");break;
149 case VFT2_DRV_INPUTMETHOD
:TRACE("INPUTMETHOD");break;
150 case VFT2_DRV_VERSIONED_PRINTER
:TRACE("VERSIONED_PRINTER");break;
153 TRACE("UNKNOWN(0x%x)",vffi
->dwFileSubtype
);break;
157 TRACE("filetype=FONT,");
158 switch (vffi
->dwFileSubtype
)
160 case VFT2_FONT_RASTER
:TRACE("RASTER");break;
161 case VFT2_FONT_VECTOR
:TRACE("VECTOR");break;
162 case VFT2_FONT_TRUETYPE
:TRACE("TRUETYPE");break;
163 default:TRACE("UNKNOWN(0x%x)",vffi
->dwFileSubtype
);break;
166 case VFT_VXD
:TRACE("filetype=VXD");break;
167 case VFT_STATIC_LIB
:TRACE("filetype=STATIC_LIB");break;
170 TRACE("filetype=Unknown(0x%x)",vffi
->dwFileType
);break;
174 TRACE("filedate=0x%x.0x%x\n",vffi
->dwFileDateMS
,vffi
->dwFileDateLS
);
177 /***********************************************************************
178 * Version Info Structure
186 #if 0 /* variable length structure */
190 VS_VERSION_INFO_STRUCT16 Children
[];
192 } VS_VERSION_INFO_STRUCT16
;
200 #if 0 /* variable length structure */
204 VS_VERSION_INFO_STRUCT32 Children
[];
206 } VS_VERSION_INFO_STRUCT32
;
208 #define VersionInfoIs16( ver ) \
209 ( ((const VS_VERSION_INFO_STRUCT16 *)ver)->szKey[0] >= ' ' )
211 #define DWORD_ALIGN( base, ptr ) \
212 ( (LPBYTE)(base) + ((((LPBYTE)(ptr) - (LPBYTE)(base)) + 3) & ~3) )
214 #define VersionInfo16_Value( ver ) \
215 DWORD_ALIGN( (ver), (ver)->szKey + strlen((ver)->szKey) + 1 )
216 #define VersionInfo32_Value( ver ) \
217 DWORD_ALIGN( (ver), (ver)->szKey + strlenW((ver)->szKey) + 1 )
219 #define VersionInfo16_Children( ver ) \
220 (const VS_VERSION_INFO_STRUCT16 *)( VersionInfo16_Value( ver ) + \
221 ( ( (ver)->wValueLength + 3 ) & ~3 ) )
222 #define VersionInfo32_Children( ver ) \
223 (const VS_VERSION_INFO_STRUCT32 *)( VersionInfo32_Value( ver ) + \
224 ( ( (ver)->wValueLength * \
225 ((ver)->wType? 2 : 1) + 3 ) & ~3 ) )
227 #define VersionInfo16_Next( ver ) \
228 (VS_VERSION_INFO_STRUCT16 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
229 #define VersionInfo32_Next( ver ) \
230 (VS_VERSION_INFO_STRUCT32 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
232 /***********************************************************************
233 * VERSION_GetFileVersionInfo_PE [internal]
235 * NOTE: returns size of the PE VERSION resource or 0xFFFFFFFF
236 * in the case the file is a PE module, but VERSION_INFO not found.
238 static DWORD
VERSION_GetFileVersionInfo_PE( LPCWSTR filename
, DWORD datasize
, LPVOID data
)
240 const VS_FIXEDFILEINFO
*vffi
;
247 TRACE("%s\n", debugstr_w(filename
));
249 hModule
= GetModuleHandleW(filename
);
251 hModule
= LoadLibraryExW(filename
, 0, LOAD_LIBRARY_AS_DATAFILE
);
253 hModule
= LoadLibraryExW(filename
, 0, 0);
256 WARN("Could not load %s\n", debugstr_w(filename
));
259 hRsrc
= FindResourceW(hModule
,
260 MAKEINTRESOURCEW(VS_VERSION_INFO
),
261 MAKEINTRESOURCEW(VS_FILE_INFO
));
264 WARN("Could not find VS_VERSION_INFO in %s\n", debugstr_w(filename
));
265 FreeLibrary(hModule
);
268 len
= SizeofResource(hModule
, hRsrc
);
269 hMem
= LoadResource(hModule
, hRsrc
);
272 WARN("Could not load VS_VERSION_INFO from %s\n", debugstr_w(filename
));
273 FreeLibrary(hModule
);
276 buf
= LockResource(hMem
);
278 vffi
= (VS_FIXEDFILEINFO
*)VersionInfo32_Value( (VS_VERSION_INFO_STRUCT32
*)buf
);
280 if ( vffi
->dwSignature
!= VS_FFI_SIGNATURE
)
282 WARN("vffi->dwSignature is 0x%08x, but not 0x%08lx!\n",
283 vffi
->dwSignature
, VS_FFI_SIGNATURE
);
289 print_vffi_debug( vffi
);
294 len
= datasize
; /* truncate data */
296 memcpy(data
, buf
, len
);
302 FreeLibrary(hModule
);
307 /***********************************************************************
308 * VERSION_GetFileVersionInfo_16 [internal]
310 * NOTE: returns size of the 16-bit VERSION resource or 0xFFFFFFFF
311 * in the case the file exists, but VERSION_INFO not found.
313 static DWORD
VERSION_GetFileVersionInfo_16( LPCSTR filename
, DWORD datasize
, LPVOID data
)
315 const VS_FIXEDFILEINFO
*vffi
;
321 char dllname
[20], owner
[20], *p
;
322 const char *basename
;
323 BOOL is_builtin
= FALSE
;
325 TRACE("%s\n", debugstr_a(filename
));
327 /* strip path information */
330 if (basename
[0] && basename
[1] == ':') basename
+= 2; /* strip drive specification */
331 if ((p
= strrchr( basename
, '\\' ))) basename
= p
+ 1;
332 if ((p
= strrchr( basename
, '/' ))) basename
= p
+ 1;
334 if (strlen(basename
) < sizeof(dllname
)-4)
338 strcpy( dllname
, basename
);
339 p
= strrchr( dllname
, '.' );
340 if (!p
) strcat( dllname
, ".dll" );
341 for (p
= dllname
; *p
; p
++) if (*p
>= 'A' && *p
<= 'Z') *p
+= 32;
343 if (wine_dll_get_owner( dllname
, owner
, sizeof(owner
), &file_exists
) == 0)
347 /* first try without loading a 16-bit module */
351 len
= GetFileResourceSize16( filename
,
352 MAKEINTRESOURCEA(VS_FILE_INFO
),
353 MAKEINTRESOURCEA(VS_VERSION_INFO
),
357 if (!data
) return len
;
359 len
= GetFileResource16( filename
,
360 MAKEINTRESOURCEA(VS_FILE_INFO
),
361 MAKEINTRESOURCEA(VS_VERSION_INFO
),
362 offset
, datasize
, data
);
365 vffi
= (VS_FIXEDFILEINFO
*)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16
*)data
);
367 if ( vffi
->dwSignature
== VS_FFI_SIGNATURE
)
369 if ( ((VS_VERSION_INFO_STRUCT16
*)data
)->wLength
< len
)
370 len
= ((VS_VERSION_INFO_STRUCT16
*)data
)->wLength
;
373 print_vffi_debug( vffi
);
380 /* this might be a builtin 16-bit module */
381 hModule
= LoadLibrary16(filename
);
384 WARN("Could not load %s\n", debugstr_a(filename
));
387 hRsrc
= FindResource16(hModule
,
388 MAKEINTRESOURCEA(VS_VERSION_INFO
),
389 MAKEINTRESOURCEA(VS_FILE_INFO
));
392 WARN("Could not find VS_VERSION_INFO in %s\n", debugstr_a(filename
));
393 FreeLibrary16(hModule
);
396 len
= SizeofResource16(hModule
, hRsrc
);
397 hMem
= LoadResource16(hModule
, hRsrc
);
400 WARN("Could not load VS_VERSION_INFO from %s\n", debugstr_a(filename
));
401 FreeLibrary16(hModule
);
404 buf
= LockResource16(hMem
);
406 if(!VersionInfoIs16(buf
))
412 vffi
= (VS_FIXEDFILEINFO
*)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16
*)buf
);
414 if ( vffi
->dwSignature
!= VS_FFI_SIGNATURE
)
416 WARN("vffi->dwSignature is 0x%08x, but not 0x%08lx!\n",
417 vffi
->dwSignature
, VS_FFI_SIGNATURE
);
423 print_vffi_debug( vffi
);
428 len
= datasize
; /* truncate data */
430 memcpy(data
, buf
, len
);
435 FreeResource16(hMem
);
436 FreeLibrary16(hModule
);
441 /***********************************************************************
442 * GetFileVersionInfoSizeW [VERSION.@]
444 DWORD WINAPI
GetFileVersionInfoSizeW( LPCWSTR filename
, LPDWORD handle
)
448 TRACE("(%s,%p)\n", debugstr_w(filename
), handle
);
450 if (handle
) *handle
= 0;
454 SetLastError(ERROR_INVALID_PARAMETER
);
459 SetLastError(ERROR_BAD_PATHNAME
);
463 len
= VERSION_GetFileVersionInfo_PE(filename
, 0, NULL
);
464 /* 0xFFFFFFFF means: file is a PE module, but VERSION_INFO not found */
465 if(len
== 0xFFFFFFFF)
467 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND
);
475 len
= WideCharToMultiByte( CP_ACP
, 0, filename
, -1, NULL
, 0, NULL
, NULL
);
476 filenameA
= HeapAlloc( GetProcessHeap(), 0, len
);
477 WideCharToMultiByte( CP_ACP
, 0, filename
, -1, filenameA
, len
, NULL
, NULL
);
479 len
= VERSION_GetFileVersionInfo_16(filenameA
, 0, NULL
);
480 HeapFree( GetProcessHeap(), 0, filenameA
);
481 /* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
484 SetLastError(ERROR_FILE_NOT_FOUND
);
487 if (len
== 0xFFFFFFFF)
489 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND
);
493 /* We have a 16bit resource.
495 * XP/W2K/W2K3 uses a buffer which is more than the actual needed space:
497 * (info->wLength - sizeof(VS_FIXEDFILEINFO)) * 4
499 * This extra buffer is used for ANSI to Unicode conversions in W-Calls.
500 * info->wLength should be the same as len. Currently it isn't but that
501 * doesn't seem to be a problem (len is bigger than info->wLength).
503 len
= (len
- sizeof(VS_FIXEDFILEINFO
)) * 4;
507 /* We have a 32bit resource.
509 * XP/W2K/W2K3 uses a buffer which is 2 times the actual needed space + 4 bytes "FE2X"
510 * This extra buffer is used for Unicode to ANSI conversions in A-Calls
519 /***********************************************************************
520 * GetFileVersionInfoSizeA [VERSION.@]
522 DWORD WINAPI
GetFileVersionInfoSizeA( LPCSTR filename
, LPDWORD handle
)
524 UNICODE_STRING filenameW
;
527 TRACE("(%s,%p)\n", debugstr_a(filename
), handle
);
530 RtlCreateUnicodeStringFromAsciiz(&filenameW
, filename
);
532 filenameW
.Buffer
= NULL
;
534 retval
= GetFileVersionInfoSizeW(filenameW
.Buffer
, handle
);
536 RtlFreeUnicodeString(&filenameW
);
541 /***********************************************************************
542 * GetFileVersionInfoW [VERSION.@]
544 BOOL WINAPI
GetFileVersionInfoW( LPCWSTR filename
, DWORD handle
,
545 DWORD datasize
, LPVOID data
)
548 VS_VERSION_INFO_STRUCT32
* vvis
= (VS_VERSION_INFO_STRUCT32
*)data
;
550 TRACE("(%s,%d,size=%d,data=%p)\n",
551 debugstr_w(filename
), handle
, datasize
, data
);
555 SetLastError(ERROR_INVALID_DATA
);
558 len
= VERSION_GetFileVersionInfo_PE(filename
, datasize
, data
);
559 /* 0xFFFFFFFF means: file is a PE module, but VERSION_INFO not found */
560 if (len
== 0xFFFFFFFF)
562 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND
);
570 len
= WideCharToMultiByte( CP_ACP
, 0, filename
, -1, NULL
, 0, NULL
, NULL
);
571 filenameA
= HeapAlloc( GetProcessHeap(), 0, len
);
572 WideCharToMultiByte( CP_ACP
, 0, filename
, -1, filenameA
, len
, NULL
, NULL
);
574 len
= VERSION_GetFileVersionInfo_16(filenameA
, datasize
, data
);
575 HeapFree( GetProcessHeap(), 0, filenameA
);
576 /* 0xFFFFFFFF means: file exists, but VERSION_INFO not found */
577 if (!len
|| len
== 0xFFFFFFFF)
579 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND
);
582 /* We have a 16bit resource. */
586 static const char signature
[] = "FE2X";
587 DWORD bufsize
= vvis
->wLength
+ strlen(signature
);
590 /* We have a 32bit resource.
592 * XP/W2K/W2K3 uses a buffer which is 2 times the actual needed space + 4 bytes "FE2X"
593 * This extra buffer is used for Unicode to ANSI conversions in A-Calls
596 /* information is truncated to datasize bytes */
597 if (datasize
>= bufsize
)
599 convbuf
= datasize
- vvis
->wLength
;
600 memcpy( ((char*)(data
))+vvis
->wLength
, signature
, convbuf
> 4 ? 4 : convbuf
);
608 /***********************************************************************
609 * GetFileVersionInfoA [VERSION.@]
611 BOOL WINAPI
GetFileVersionInfoA( LPCSTR filename
, DWORD handle
,
612 DWORD datasize
, LPVOID data
)
614 UNICODE_STRING filenameW
;
617 TRACE("(%s,%d,size=%d,data=%p)\n",
618 debugstr_a(filename
), handle
, datasize
, data
);
621 RtlCreateUnicodeStringFromAsciiz(&filenameW
, filename
);
623 filenameW
.Buffer
= NULL
;
625 retval
= GetFileVersionInfoW(filenameW
.Buffer
, handle
, datasize
, data
);
627 RtlFreeUnicodeString(&filenameW
);
632 /***********************************************************************
633 * VersionInfo16_FindChild [internal]
635 static const VS_VERSION_INFO_STRUCT16
*VersionInfo16_FindChild( const VS_VERSION_INFO_STRUCT16
*info
,
636 LPCSTR szKey
, UINT cbKey
)
638 const VS_VERSION_INFO_STRUCT16
*child
= VersionInfo16_Children( info
);
640 while ((char *)child
< (char *)info
+ info
->wLength
)
642 if (!strncasecmp( child
->szKey
, szKey
, cbKey
) && !child
->szKey
[cbKey
])
645 if (!(child
->wLength
)) return NULL
;
646 child
= VersionInfo16_Next( child
);
652 /***********************************************************************
653 * VersionInfo32_FindChild [internal]
655 static const VS_VERSION_INFO_STRUCT32
*VersionInfo32_FindChild( const VS_VERSION_INFO_STRUCT32
*info
,
656 LPCWSTR szKey
, UINT cbKey
)
658 const VS_VERSION_INFO_STRUCT32
*child
= VersionInfo32_Children( info
);
660 while ((char *)child
< (char *)info
+ info
->wLength
)
662 if (!strncmpiW( child
->szKey
, szKey
, cbKey
) && !child
->szKey
[cbKey
])
665 child
= VersionInfo32_Next( child
);
671 /***********************************************************************
672 * VersionInfo16_QueryValue [internal]
674 * Gets a value from a 16-bit NE resource
676 static BOOL WINAPI
VersionInfo16_QueryValue( const VS_VERSION_INFO_STRUCT16
*info
, LPCSTR lpSubBlock
,
677 LPVOID
*lplpBuffer
, UINT
*puLen
)
679 while ( *lpSubBlock
)
681 /* Find next path component */
683 for ( lpNextSlash
= lpSubBlock
; *lpNextSlash
; lpNextSlash
++ )
684 if ( *lpNextSlash
== '\\' )
687 /* Skip empty components */
688 if ( lpNextSlash
== lpSubBlock
)
694 /* We have a non-empty component: search info for key */
695 info
= VersionInfo16_FindChild( info
, lpSubBlock
, lpNextSlash
-lpSubBlock
);
698 if (puLen
) *puLen
= 0 ;
699 SetLastError( ERROR_RESOURCE_TYPE_NOT_FOUND
);
703 /* Skip path component */
704 lpSubBlock
= lpNextSlash
;
708 *lplpBuffer
= VersionInfo16_Value( info
);
710 *puLen
= info
->wValueLength
;
715 /***********************************************************************
716 * VersionInfo32_QueryValue [internal]
718 * Gets a value from a 32-bit PE resource
720 static BOOL WINAPI
VersionInfo32_QueryValue( const VS_VERSION_INFO_STRUCT32
*info
, LPCWSTR lpSubBlock
,
721 LPVOID
*lplpBuffer
, UINT
*puLen
)
723 TRACE("lpSubBlock : (%s)\n", debugstr_w(lpSubBlock
));
725 while ( *lpSubBlock
)
727 /* Find next path component */
729 for ( lpNextSlash
= lpSubBlock
; *lpNextSlash
; lpNextSlash
++ )
730 if ( *lpNextSlash
== '\\' )
733 /* Skip empty components */
734 if ( lpNextSlash
== lpSubBlock
)
740 /* We have a non-empty component: search info for key */
741 info
= VersionInfo32_FindChild( info
, lpSubBlock
, lpNextSlash
-lpSubBlock
);
744 if (puLen
) *puLen
= 0 ;
745 SetLastError( ERROR_RESOURCE_TYPE_NOT_FOUND
);
749 /* Skip path component */
750 lpSubBlock
= lpNextSlash
;
754 *lplpBuffer
= VersionInfo32_Value( info
);
756 *puLen
= info
->wValueLength
;
761 /***********************************************************************
762 * VerQueryValueA [VERSION.@]
764 BOOL WINAPI
VerQueryValueA( LPCVOID pBlock
, LPCSTR lpSubBlock
,
765 LPVOID
*lplpBuffer
, UINT
*puLen
)
767 static const char rootA
[] = "\\";
768 static const char varfileinfoA
[] = "\\VarFileInfo\\Translation";
769 const VS_VERSION_INFO_STRUCT16
*info
= (const VS_VERSION_INFO_STRUCT16
*)pBlock
;
771 TRACE("(%p,%s,%p,%p)\n",
772 pBlock
, debugstr_a(lpSubBlock
), lplpBuffer
, puLen
);
777 if ( !VersionInfoIs16( info
) )
783 len
= MultiByteToWideChar(CP_ACP
, 0, lpSubBlock
, -1, NULL
, 0);
784 lpSubBlockW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
789 MultiByteToWideChar(CP_ACP
, 0, lpSubBlock
, -1, lpSubBlockW
, len
);
791 ret
= VersionInfo32_QueryValue(pBlock
, lpSubBlockW
, lplpBuffer
, puLen
);
793 HeapFree(GetProcessHeap(), 0, lpSubBlockW
);
795 if (ret
&& strcasecmp( lpSubBlock
, rootA
) && strcasecmp( lpSubBlock
, varfileinfoA
))
797 /* Set lpBuffer so it points to the 'empty' area where we store
798 * the converted strings
800 LPSTR lpBufferA
= (LPSTR
)pBlock
+ info
->wLength
+ 4;
801 DWORD pos
= (LPCSTR
)*lplpBuffer
- (LPCSTR
)pBlock
;
803 len
= WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)*lplpBuffer
, -1,
804 lpBufferA
+ pos
, info
->wLength
- pos
, NULL
, NULL
);
805 *lplpBuffer
= lpBufferA
+ pos
;
811 return VersionInfo16_QueryValue(info
, lpSubBlock
, lplpBuffer
, puLen
);
814 /***********************************************************************
815 * VerQueryValueW [VERSION.@]
817 BOOL WINAPI
VerQueryValueW( LPCVOID pBlock
, LPCWSTR lpSubBlock
,
818 LPVOID
*lplpBuffer
, UINT
*puLen
)
820 static const WCHAR rootW
[] = { '\\', 0 };
821 static const WCHAR varfileinfoW
[] = { '\\','V','a','r','F','i','l','e','I','n','f','o',
822 '\\','T','r','a','n','s','l','a','t','i','o','n', 0 };
824 const VS_VERSION_INFO_STRUCT32
*info
= (const VS_VERSION_INFO_STRUCT32
*)pBlock
;
826 TRACE("(%p,%s,%p,%p)\n",
827 pBlock
, debugstr_w(lpSubBlock
), lplpBuffer
, puLen
);
832 if ( VersionInfoIs16( info
) )
838 len
= WideCharToMultiByte(CP_ACP
, 0, lpSubBlock
, -1, NULL
, 0, NULL
, NULL
);
839 lpSubBlockA
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(char));
844 WideCharToMultiByte(CP_ACP
, 0, lpSubBlock
, -1, lpSubBlockA
, len
, NULL
, NULL
);
846 ret
= VersionInfo16_QueryValue(pBlock
, lpSubBlockA
, lplpBuffer
, puLen
);
848 HeapFree(GetProcessHeap(), 0, lpSubBlockA
);
850 if (ret
&& strcmpiW( lpSubBlock
, rootW
) && strcmpiW( lpSubBlock
, varfileinfoW
))
852 /* Set lpBuffer so it points to the 'empty' area where we store
853 * the converted strings
855 LPWSTR lpBufferW
= (LPWSTR
)((LPSTR
)pBlock
+ info
->wLength
);
856 DWORD pos
= (LPCSTR
)*lplpBuffer
- (LPCSTR
)pBlock
;
857 DWORD max
= (info
->wLength
- sizeof(VS_FIXEDFILEINFO
)) * 4 - info
->wLength
;
859 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)*lplpBuffer
, -1,
860 lpBufferW
+ pos
, max
/sizeof(WCHAR
) - pos
);
861 *lplpBuffer
= lpBufferW
+ pos
;
867 return VersionInfo32_QueryValue(info
, lpSubBlock
, lplpBuffer
, puLen
);