mscoree: Implement ICLRMetaHost_GetVersionFromFile.
[wine] / dlls / mscoree / metahost.c
1 /*
2  * ICLRMetaHost - discovery and management of available .NET runtimes
3  *
4  * Copyright 2010 Vincent Povirk for CodeWeavers
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
23 #define COBJMACROS
24
25 #include "wine/unicode.h"
26 #include "wine/library.h"
27 #include "windef.h"
28 #include "winbase.h"
29 #include "ole2.h"
30
31 #include "mscoree.h"
32 #include "metahost.h"
33 #include "mscoree_private.h"
34
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
38
39 struct CLRMetaHost
40 {
41     const struct ICLRMetaHostVtbl *CLRMetaHost_vtbl;
42 };
43
44 static const struct CLRMetaHost GlobalCLRMetaHost;
45
46 static HRESULT WINAPI CLRMetaHost_QueryInterface(ICLRMetaHost* iface,
47         REFIID riid,
48         void **ppvObject)
49 {
50     TRACE("%s %p\n", debugstr_guid(riid), ppvObject);
51
52     if ( IsEqualGUID( riid, &IID_ICLRMetaHost ) ||
53          IsEqualGUID( riid, &IID_IUnknown ) )
54     {
55         *ppvObject = iface;
56     }
57     else
58     {
59         FIXME("Unsupported interface %s\n", debugstr_guid(riid));
60         return E_NOINTERFACE;
61     }
62
63     ICLRMetaHost_AddRef( iface );
64
65     return S_OK;
66 }
67
68 static ULONG WINAPI CLRMetaHost_AddRef(ICLRMetaHost* iface)
69 {
70     return 2;
71 }
72
73 static ULONG WINAPI CLRMetaHost_Release(ICLRMetaHost* iface)
74 {
75     return 1;
76 }
77
78 static HRESULT WINAPI CLRMetaHost_GetRuntime(ICLRMetaHost* iface,
79     LPCWSTR pwzVersion, REFIID iid, LPVOID *ppRuntime)
80 {
81     FIXME("%s %s %p\n", debugstr_w(pwzVersion), debugstr_guid(iid), ppRuntime);
82
83     return E_NOTIMPL;
84 }
85
86 static HRESULT WINAPI CLRMetaHost_GetVersionFromFile(ICLRMetaHost* iface,
87     LPCWSTR pwzFilePath, LPWSTR pwzBuffer, DWORD *pcchBuffer)
88 {
89     ASSEMBLY *assembly;
90     HRESULT hr;
91     LPSTR version;
92     ULONG buffer_size=*pcchBuffer;
93
94     TRACE("%s %p %p\n", debugstr_w(pwzFilePath), pwzBuffer, pcchBuffer);
95
96     hr = assembly_create(&assembly, pwzFilePath);
97
98     if (SUCCEEDED(hr))
99     {
100         hr = assembly_get_runtime_version(assembly, &version);
101
102         if (SUCCEEDED(hr))
103         {
104             *pcchBuffer = MultiByteToWideChar(CP_UTF8, 0, version, -1, NULL, 0);
105
106             if (pwzBuffer)
107             {
108                 if (buffer_size >= *pcchBuffer)
109                     MultiByteToWideChar(CP_UTF8, 0, version, -1, pwzBuffer, buffer_size);
110                 else
111                     hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
112             }
113         }
114
115         assembly_release(assembly);
116     }
117
118     return hr;
119 }
120
121 static HRESULT WINAPI CLRMetaHost_EnumerateInstalledRuntimes(ICLRMetaHost* iface,
122     IEnumUnknown **ppEnumerator)
123 {
124     FIXME("%p\n", ppEnumerator);
125
126     return E_NOTIMPL;
127 }
128
129 static HRESULT WINAPI CLRMetaHost_EnumerateLoadedRuntimes(ICLRMetaHost* iface,
130     HANDLE hndProcess, IEnumUnknown **ppEnumerator)
131 {
132     FIXME("%p %p\n", hndProcess, ppEnumerator);
133
134     return E_NOTIMPL;
135 }
136
137 static HRESULT WINAPI CLRMetaHost_RequestRuntimeLoadedNotification(ICLRMetaHost* iface,
138     RuntimeLoadedCallbackFnPtr pCallbackFunction)
139 {
140     FIXME("%p\n", pCallbackFunction);
141
142     return E_NOTIMPL;
143 }
144
145 static HRESULT WINAPI CLRMetaHost_QueryLegacyV2RuntimeBinding(ICLRMetaHost* iface,
146     REFIID riid, LPVOID *ppUnk)
147 {
148     FIXME("%s %p\n", debugstr_guid(riid), ppUnk);
149
150     return E_NOTIMPL;
151 }
152
153 static HRESULT WINAPI CLRMetaHost_ExitProcess(ICLRMetaHost* iface, INT32 iExitCode)
154 {
155     FIXME("%i: stub\n", iExitCode);
156
157     ExitProcess(iExitCode);
158 }
159
160 static const struct ICLRMetaHostVtbl CLRMetaHost_vtbl =
161 {
162     CLRMetaHost_QueryInterface,
163     CLRMetaHost_AddRef,
164     CLRMetaHost_Release,
165     CLRMetaHost_GetRuntime,
166     CLRMetaHost_GetVersionFromFile,
167     CLRMetaHost_EnumerateInstalledRuntimes,
168     CLRMetaHost_EnumerateLoadedRuntimes,
169     CLRMetaHost_RequestRuntimeLoadedNotification,
170     CLRMetaHost_QueryLegacyV2RuntimeBinding,
171     CLRMetaHost_ExitProcess
172 };
173
174 static const struct CLRMetaHost GlobalCLRMetaHost = {
175     &CLRMetaHost_vtbl
176 };
177
178 extern HRESULT CLRMetaHost_CreateInstance(REFIID riid, void **ppobj)
179 {
180     return ICLRMetaHost_QueryInterface((ICLRMetaHost*)&GlobalCLRMetaHost, riid, ppobj);
181 }