Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/winecrt0/dll_version.c
12343 views
1
/*
2
* DllGetVersion default implementation
3
*
4
* Copyright 2025 Alexandre Julliard
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19
*/
20
21
#include <stdarg.h>
22
#include "windef.h"
23
#include "winbase.h"
24
#include "shlwapi.h"
25
26
static inline void *image_base(void)
27
{
28
#ifdef __WINE_PE_BUILD
29
extern IMAGE_DOS_HEADER __ImageBase;
30
return (void *)&__ImageBase;
31
#else
32
extern IMAGE_NT_HEADERS __wine_spec_nt_header;
33
return (void *)((__wine_spec_nt_header.OptionalHeader.ImageBase + 0xffff) & ~0xffff);
34
#endif
35
}
36
37
struct version_info
38
{
39
WORD len;
40
WORD val_len;
41
WORD type;
42
WCHAR key[];
43
};
44
45
#define GET_VERSION_VALUE(info) ((void *)((char *)info + ((offsetof(struct version_info, key[lstrlenW(info->key) + 1]) + 3) & ~3)))
46
47
HRESULT WINAPI DllGetVersion( DLLVERSIONINFO *info )
48
{
49
HRSRC rsrc;
50
HMODULE module = image_base();
51
struct version_info *data;
52
VS_FIXEDFILEINFO *fileinfo;
53
DLLVERSIONINFO2 *info2 = (DLLVERSIONINFO2 *)info;
54
55
if (!info) return E_INVALIDARG;
56
if (!(rsrc = FindResourceW( module, (LPWSTR)VS_VERSION_INFO, (LPWSTR)VS_FILE_INFO ))) return E_INVALIDARG;
57
if (!(data = LoadResource( module, rsrc ))) return E_INVALIDARG;
58
if (data->val_len < sizeof(*fileinfo)) return E_INVALIDARG;
59
fileinfo = GET_VERSION_VALUE( data );
60
if (fileinfo->dwSignature != VS_FFI_SIGNATURE) return E_INVALIDARG;
61
62
switch (info->cbSize)
63
{
64
case sizeof(DLLVERSIONINFO2):
65
info2->dwFlags = 0;
66
info2->ullVersion = ((ULONGLONG)fileinfo->dwFileVersionMS << 32) | fileinfo->dwFileVersionLS;
67
/* fall through */
68
case sizeof(DLLVERSIONINFO):
69
info->dwMajorVersion = HIWORD( fileinfo->dwFileVersionMS );
70
info->dwMinorVersion = LOWORD( fileinfo->dwFileVersionMS );
71
info->dwBuildNumber = HIWORD( fileinfo->dwFileVersionLS );
72
info->dwPlatformID = DLLVER_PLATFORM_NT;
73
return S_OK;
74
default:
75
return E_INVALIDARG;
76
}
77
}
78
79