gdi32: Allow a driver to implement SelectBitmap but not CreateBitmap.
[wine] / dlls / mscoree / mscoree_main.c
1 /*
2  * Implementation of mscoree.dll
3  * Microsoft Component Object Runtime Execution Engine
4  *
5  * Copyright 2006 Paul Chitescu
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include <stdarg.h>
23
24 #define COBJMACROS
25 #include "wine/unicode.h"
26 #include "wine/library.h"
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "winreg.h"
32 #include "ole2.h"
33 #include "ocidl.h"
34 #include "shellapi.h"
35
36 #include "initguid.h"
37 #include "msxml2.h"
38 #include "corerror.h"
39 #include "cor.h"
40 #include "mscoree.h"
41 #include "corhdr.h"
42 #include "cordebug.h"
43 #include "metahost.h"
44 #include "fusion.h"
45 #include "wine/list.h"
46 #include "mscoree_private.h"
47 #include "rpcproxy.h"
48
49 #include "wine/debug.h"
50
51 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
52
53 static HINSTANCE MSCOREE_hInstance;
54
55 typedef HRESULT (*fnCreateInstance)(REFIID riid, LPVOID *ppObj);
56
57 char *WtoA(LPCWSTR wstr)
58 {
59     int length;
60     char *result;
61
62     length = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
63
64     result = HeapAlloc(GetProcessHeap(), 0, length);
65
66     if (result)
67         WideCharToMultiByte(CP_UTF8, 0, wstr, -1, result, length, NULL, NULL);
68
69     return result;
70 }
71
72 static BOOL get_install_root(LPWSTR install_dir)
73 {
74     const WCHAR dotnet_key[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\','.','N','E','T','F','r','a','m','e','w','o','r','k','\\',0};
75     const WCHAR install_root[] = {'I','n','s','t','a','l','l','R','o','o','t',0};
76
77     DWORD len;
78     HKEY key;
79
80     if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, dotnet_key, 0, KEY_READ, &key))
81         return FALSE;
82
83     len = MAX_PATH;
84     if (RegQueryValueExW(key, install_root, 0, NULL, (LPBYTE)install_dir, &len))
85     {
86         RegCloseKey(key);
87         return FALSE;
88     }
89     RegCloseKey(key);
90
91     return TRUE;
92 }
93
94 typedef struct mscorecf
95 {
96     IClassFactory    IClassFactory_iface;
97     LONG ref;
98
99     fnCreateInstance pfnCreateInstance;
100
101     CLSID clsid;
102 } mscorecf;
103
104 static inline mscorecf *impl_from_IClassFactory( IClassFactory *iface )
105 {
106     return CONTAINING_RECORD(iface, mscorecf, IClassFactory_iface);
107 }
108
109 static HRESULT WINAPI mscorecf_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppobj )
110 {
111     TRACE("%s %p\n", debugstr_guid(riid), ppobj);
112
113     if (IsEqualGUID(riid, &IID_IUnknown) ||
114         IsEqualGUID(riid, &IID_IClassFactory))
115     {
116         IClassFactory_AddRef( iface );
117         *ppobj = iface;
118         return S_OK;
119     }
120
121     ERR("interface %s not implemented\n", debugstr_guid(riid));
122     return E_NOINTERFACE;
123 }
124
125 static ULONG WINAPI mscorecf_AddRef(IClassFactory *iface )
126 {
127     mscorecf *This = impl_from_IClassFactory(iface);
128     ULONG ref = InterlockedIncrement(&This->ref);
129
130     TRACE("%p ref=%u\n", This, ref);
131
132     return ref;
133 }
134
135 static ULONG WINAPI mscorecf_Release(IClassFactory *iface )
136 {
137     mscorecf *This = impl_from_IClassFactory(iface);
138     ULONG ref = InterlockedDecrement(&This->ref);
139
140     TRACE("%p ref=%u\n", This, ref);
141
142     if (ref == 0)
143     {
144         HeapFree(GetProcessHeap(), 0, This);
145     }
146
147     return ref;
148 }
149
150 static HRESULT WINAPI mscorecf_CreateInstance(IClassFactory *iface,LPUNKNOWN pOuter,
151                             REFIID riid, LPVOID *ppobj )
152 {
153     mscorecf *This = impl_from_IClassFactory( iface );
154     HRESULT hr;
155     IUnknown *punk;
156
157     TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj );
158
159     *ppobj = NULL;
160
161     if (pOuter)
162         return CLASS_E_NOAGGREGATION;
163
164     hr = This->pfnCreateInstance( &This->clsid, (LPVOID*) &punk );
165     if (SUCCEEDED(hr))
166     {
167         hr = IUnknown_QueryInterface( punk, riid, ppobj );
168
169         IUnknown_Release( punk );
170     }
171     else
172     {
173         WARN("Cannot create an instance object. 0x%08x\n", hr);
174     }
175     return hr;
176 }
177
178 static HRESULT WINAPI mscorecf_LockServer(IClassFactory *iface, BOOL dolock)
179 {
180     FIXME("(%p)->(%d),stub!\n",iface,dolock);
181     return S_OK;
182 }
183
184 static const struct IClassFactoryVtbl mscorecf_vtbl =
185 {
186     mscorecf_QueryInterface,
187     mscorecf_AddRef,
188     mscorecf_Release,
189     mscorecf_CreateInstance,
190     mscorecf_LockServer
191 };
192
193 HRESULT WINAPI CorBindToRuntimeHost(LPCWSTR pwszVersion, LPCWSTR pwszBuildFlavor,
194                                     LPCWSTR pwszHostConfigFile, VOID *pReserved,
195                                     DWORD startupFlags, REFCLSID rclsid,
196                                     REFIID riid, LPVOID *ppv)
197 {
198     HRESULT ret;
199     ICLRRuntimeInfo *info;
200
201     TRACE("(%s, %s, %s, %p, %d, %s, %s, %p)\n", debugstr_w(pwszVersion),
202           debugstr_w(pwszBuildFlavor), debugstr_w(pwszHostConfigFile), pReserved,
203           startupFlags, debugstr_guid(rclsid), debugstr_guid(riid), ppv);
204
205     *ppv = NULL;
206
207     ret = get_runtime_info(NULL, pwszVersion, pwszHostConfigFile, startupFlags, 0, TRUE, &info);
208
209     if (SUCCEEDED(ret))
210     {
211         ret = ICLRRuntimeInfo_GetInterface(info, rclsid, riid, ppv);
212
213         ICLRRuntimeInfo_Release(info);
214     }
215
216     return ret;
217 }
218
219 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
220 {
221     TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
222
223     MSCOREE_hInstance = hinstDLL;
224
225     switch (fdwReason)
226     {
227     case DLL_WINE_PREATTACH:
228         return FALSE;  /* prefer native version */
229     case DLL_PROCESS_ATTACH:
230         DisableThreadLibraryCalls(hinstDLL);
231         break;
232     case DLL_PROCESS_DETACH:
233         expect_no_runtimes();
234         break;
235     }
236     return TRUE;
237 }
238
239 __int32 WINAPI _CorExeMain2(PBYTE ptrMemory, DWORD cntMemory, LPWSTR imageName, LPWSTR loaderName, LPWSTR cmdLine)
240 {
241     TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory, cntMemory, debugstr_w(imageName), debugstr_w(loaderName), debugstr_w(cmdLine));
242     FIXME("Directly running .NET applications not supported.\n");
243     return -1;
244 }
245
246 void WINAPI CorExitProcess(int exitCode)
247 {
248     TRACE("(%x)\n", exitCode);
249     unload_all_runtimes();
250     ExitProcess(exitCode);
251 }
252
253 VOID WINAPI _CorImageUnloading(PVOID imageBase)
254 {
255     TRACE("(%p): stub\n", imageBase);
256 }
257
258 HRESULT WINAPI _CorValidateImage(PVOID* imageBase, LPCWSTR imageName)
259 {
260     TRACE("(%p, %s): stub\n", imageBase, debugstr_w(imageName));
261     return E_FAIL;
262 }
263
264 HRESULT WINAPI GetCORSystemDirectory(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
265 {
266     ICLRRuntimeInfo *info;
267     HRESULT ret;
268
269     TRACE("(%p, %d, %p)!\n", pbuffer, cchBuffer, dwLength);
270
271     if (!dwLength || !pbuffer)
272         return E_POINTER;
273
274     ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
275
276     if (SUCCEEDED(ret))
277     {
278         *dwLength = cchBuffer;
279         ret = ICLRRuntimeInfo_GetRuntimeDirectory(info, pbuffer, dwLength);
280
281         ICLRRuntimeInfo_Release(info);
282     }
283
284     return ret;
285 }
286
287 HRESULT WINAPI GetCORVersion(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
288 {
289     ICLRRuntimeInfo *info;
290     HRESULT ret;
291
292     TRACE("(%p, %d, %p)!\n", pbuffer, cchBuffer, dwLength);
293
294     if (!dwLength || !pbuffer)
295         return E_POINTER;
296
297     ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
298
299     if (SUCCEEDED(ret))
300     {
301         *dwLength = cchBuffer;
302         ret = ICLRRuntimeInfo_GetVersionString(info, pbuffer, dwLength);
303
304         ICLRRuntimeInfo_Release(info);
305     }
306
307     return ret;
308 }
309
310 HRESULT WINAPI GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWSTR pConfigurationFile,
311     DWORD startupFlags, DWORD runtimeInfoFlags, LPWSTR pDirectory, DWORD dwDirectory, DWORD *dwDirectoryLength,
312     LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength)
313 {
314     HRESULT ret;
315     ICLRRuntimeInfo *info;
316     DWORD length_dummy;
317
318     TRACE("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p)\n", debugstr_w(pExe),
319           debugstr_w(pwszVersion), debugstr_w(pConfigurationFile), startupFlags, runtimeInfoFlags, pDirectory,
320           dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength);
321
322     if (!dwDirectoryLength) dwDirectoryLength = &length_dummy;
323
324     if (!dwlength) dwlength = &length_dummy;
325
326     ret = get_runtime_info(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, TRUE, &info);
327
328     if (SUCCEEDED(ret))
329     {
330         *dwlength = cchBuffer;
331         ret = ICLRRuntimeInfo_GetVersionString(info, pVersion, dwlength);
332
333         if (SUCCEEDED(ret))
334         {
335             if(pwszVersion)
336                 pVersion[0] = pwszVersion[0];
337
338             *dwDirectoryLength = dwDirectory;
339             ret = ICLRRuntimeInfo_GetRuntimeDirectory(info, pDirectory, dwDirectoryLength);
340         }
341
342         ICLRRuntimeInfo_Release(info);
343     }
344
345     return ret;
346 }
347
348 HRESULT WINAPI GetRequestedRuntimeVersion(LPWSTR pExe, LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength)
349 {
350     TRACE("(%s, %p, %d, %p)\n", debugstr_w(pExe), pVersion, cchBuffer, dwlength);
351
352     if(!dwlength)
353         return E_POINTER;
354
355     return GetRequestedRuntimeInfo(pExe, NULL, NULL, 0, 0, NULL, 0, NULL, pVersion, cchBuffer, dwlength);
356 }
357
358 HRESULT WINAPI GetRealProcAddress(LPCSTR procname, void **ppv)
359 {
360     FIXME("(%s, %p)\n", debugstr_a(procname), ppv);
361     return CLR_E_SHIM_RUNTIMEEXPORT;
362 }
363
364 HRESULT WINAPI GetFileVersion(LPCWSTR szFilename, LPWSTR szBuffer, DWORD cchBuffer, DWORD *dwLength)
365 {
366     TRACE("(%s, %p, %d, %p)\n", debugstr_w(szFilename), szBuffer, cchBuffer, dwLength);
367
368     if (!szFilename || !dwLength)
369         return E_POINTER;
370
371     *dwLength = cchBuffer;
372     return CLRMetaHost_GetVersionFromFile(0, szFilename, szBuffer, dwLength);
373 }
374
375 HRESULT WINAPI LoadLibraryShim( LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE * phModDll)
376 {
377     HRESULT ret=S_OK;
378     WCHAR dll_filename[MAX_PATH];
379     WCHAR version[MAX_PATH];
380     static const WCHAR default_version[] = {'v','1','.','1','.','4','3','2','2',0};
381     static const WCHAR slash[] = {'\\',0};
382     DWORD dummy;
383
384     TRACE("(%p %s, %p, %p, %p)\n", szDllName, debugstr_w(szDllName), szVersion, pvReserved, phModDll);
385
386     if (!szDllName || !phModDll)
387         return E_POINTER;
388
389     if (!get_install_root(dll_filename))
390     {
391         ERR("error reading registry key for installroot\n");
392         dll_filename[0] = 0;
393     }
394     else
395     {
396         if (!szVersion)
397         {
398             ret = GetCORVersion(version, MAX_PATH, &dummy);
399             if (SUCCEEDED(ret))
400                 szVersion = version;
401             else
402                 szVersion = default_version;
403         }
404         strcatW(dll_filename, szVersion);
405         strcatW(dll_filename, slash);
406     }
407
408     strcatW(dll_filename, szDllName);
409
410     *phModDll = LoadLibraryW(dll_filename);
411
412     return *phModDll ? S_OK : E_HANDLE;
413 }
414
415 HRESULT WINAPI LockClrVersion(FLockClrVersionCallback hostCallback, FLockClrVersionCallback *pBeginHostSetup, FLockClrVersionCallback *pEndHostSetup)
416 {
417     FIXME("(%p %p %p): stub\n", hostCallback, pBeginHostSetup, pEndHostSetup);
418     return S_OK;
419 }
420
421 HRESULT WINAPI CoInitializeCor(DWORD fFlags)
422 {
423     FIXME("(0x%08x): stub\n", fFlags);
424     return S_OK;
425 }
426
427 HRESULT WINAPI GetAssemblyMDImport(LPCWSTR szFileName, REFIID riid, IUnknown **ppIUnk)
428 {
429     FIXME("(%p %s, %s, %p): stub\n", szFileName, debugstr_w(szFileName), debugstr_guid(riid), *ppIUnk);
430     return ERROR_CALL_NOT_IMPLEMENTED;
431 }
432
433 HRESULT WINAPI GetVersionFromProcess(HANDLE hProcess, LPWSTR pVersion, DWORD cchBuffer, DWORD *dwLength)
434 {
435     FIXME("(%p, %p, %d, %p): stub\n", hProcess, pVersion, cchBuffer, dwLength);
436     return E_NOTIMPL;
437 }
438
439 HRESULT WINAPI LoadStringRCEx(LCID culture, UINT resId, LPWSTR pBuffer, int iBufLen, int bQuiet, int* pBufLen)
440 {
441     HRESULT res = S_OK;
442     if ((iBufLen <= 0) || !pBuffer)
443         return E_INVALIDARG;
444     pBuffer[0] = 0;
445     if (resId) {
446         FIXME("(%d, %x, %p, %d, %d, %p): semi-stub\n", culture, resId, pBuffer, iBufLen, bQuiet, pBufLen);
447         res = E_NOTIMPL;
448     }
449     else
450         res = E_FAIL;
451     if (pBufLen)
452         *pBufLen = lstrlenW(pBuffer);
453     return res;
454 }
455
456 HRESULT WINAPI LoadStringRC(UINT resId, LPWSTR pBuffer, int iBufLen, int bQuiet)
457 {
458     return LoadStringRCEx(-1, resId, pBuffer, iBufLen, bQuiet, NULL);
459 }
460
461 HRESULT WINAPI CorBindToRuntimeEx(LPWSTR szVersion, LPWSTR szBuildFlavor, DWORD nflags, REFCLSID rslsid,
462                                   REFIID riid, LPVOID *ppv)
463 {
464     HRESULT ret;
465     ICLRRuntimeInfo *info;
466
467     TRACE("%s %s %d %s %s %p\n", debugstr_w(szVersion), debugstr_w(szBuildFlavor), nflags, debugstr_guid( rslsid ),
468           debugstr_guid( riid ), ppv);
469
470     *ppv = NULL;
471
472     ret = get_runtime_info(NULL, szVersion, NULL, nflags, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
473
474     if (SUCCEEDED(ret))
475     {
476         ret = ICLRRuntimeInfo_GetInterface(info, rslsid, riid, ppv);
477
478         ICLRRuntimeInfo_Release(info);
479     }
480
481     return ret;
482 }
483
484 HRESULT WINAPI CorBindToCurrentRuntime(LPCWSTR filename, REFCLSID rclsid, REFIID riid, LPVOID *ppv)
485 {
486     FIXME("(%s, %s, %s, %p): stub\n", debugstr_w(filename), debugstr_guid(rclsid), debugstr_guid(riid), ppv);
487     return E_NOTIMPL;
488 }
489
490 STDAPI ClrCreateManagedInstance(LPCWSTR pTypeName, REFIID riid, void **ppObject)
491 {
492     HRESULT ret;
493     ICLRRuntimeInfo *info;
494     RuntimeHost *host;
495     MonoObject *obj;
496     IUnknown *unk;
497
498     TRACE("(%s,%s,%p)\n", debugstr_w(pTypeName), debugstr_guid(riid), ppObject);
499
500     /* FIXME: How to determine which runtime version to use? */
501     ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
502
503     if (SUCCEEDED(ret))
504     {
505         ret = ICLRRuntimeInfo_GetRuntimeHost(info, &host);
506
507         ICLRRuntimeInfo_Release(info);
508     }
509
510     if (SUCCEEDED(ret))
511         ret = RuntimeHost_CreateManagedInstance(host, pTypeName, NULL, &obj);
512
513     if (SUCCEEDED(ret))
514         ret = RuntimeHost_GetIUnknownForObject(host, obj, &unk);
515
516     if (SUCCEEDED(ret))
517     {
518         ret = IUnknown_QueryInterface(unk, riid, ppObject);
519         IUnknown_Release(unk);
520     }
521
522     return ret;
523 }
524
525 BOOL WINAPI StrongNameSignatureVerification(LPCWSTR filename, DWORD inFlags, DWORD* pOutFlags)
526 {
527     FIXME("(%s, 0x%X, %p): stub\n", debugstr_w(filename), inFlags, pOutFlags);
528     return FALSE;
529 }
530
531 BOOL WINAPI StrongNameSignatureVerificationEx(LPCWSTR filename, BOOL forceVerification, BOOL* pVerified)
532 {
533     FIXME("(%s, %u, %p): stub\n", debugstr_w(filename), forceVerification, pVerified);
534     return FALSE;
535 }
536
537 HRESULT WINAPI CreateConfigStream(LPCWSTR filename, IStream **stream)
538 {
539     FIXME("(%s, %p): stub\n", debugstr_w(filename), stream);
540     return E_NOTIMPL;
541 }
542
543 HRESULT WINAPI CreateDebuggingInterfaceFromVersion(int nDebugVersion, LPCWSTR version, IUnknown **ppv)
544 {
545     const WCHAR v2_0[] = {'v','2','.','0','.','5','0','7','2','7',0};
546     HRESULT hr = E_FAIL;
547     ICLRRuntimeInfo *runtimeinfo;
548
549     if(nDebugVersion < 1 || nDebugVersion > 4)
550         return E_INVALIDARG;
551
552     TRACE("(%d %s, %p): stub\n", nDebugVersion, debugstr_w(version), ppv);
553
554     if(!ppv)
555         return E_INVALIDARG;
556
557     *ppv = NULL;
558
559     if(strcmpW(version, v2_0) != 0)
560     {
561         FIXME("Currently .NET Version '%s' not support.\n", debugstr_w(version));
562         return E_INVALIDARG;
563     }
564
565     if(nDebugVersion != 3)
566         return E_INVALIDARG;
567
568     hr = CLRMetaHost_GetRuntime(0, version, &IID_ICLRRuntimeInfo, (void**)&runtimeinfo);
569     if(hr == S_OK)
570     {
571         hr = ICLRRuntimeInfo_GetInterface(runtimeinfo, &CLSID_CLRDebuggingLegacy, &IID_ICorDebug, (void**)ppv);
572
573         ICLRRuntimeInfo_Release(runtimeinfo);
574     }
575
576     if(!*ppv)
577         return E_FAIL;
578
579     return hr;
580 }
581
582 HRESULT WINAPI CLRCreateInstance(REFCLSID clsid, REFIID riid, LPVOID *ppInterface)
583 {
584     TRACE("(%s,%s,%p)\n", debugstr_guid(clsid), debugstr_guid(riid), ppInterface);
585
586     if (IsEqualGUID(clsid, &CLSID_CLRMetaHost))
587         return CLRMetaHost_CreateInstance(riid, ppInterface);
588
589     FIXME("not implemented for class %s\n", debugstr_guid(clsid));
590
591     return CLASS_E_CLASSNOTAVAILABLE;
592 }
593
594 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
595 {
596     mscorecf *This;
597     HRESULT hr;
598
599     TRACE("(%s, %s, %p): stub\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
600
601     if(!ppv)
602         return E_INVALIDARG;
603
604     This = HeapAlloc(GetProcessHeap(), 0, sizeof(mscorecf));
605
606     This->IClassFactory_iface.lpVtbl = &mscorecf_vtbl;
607     This->pfnCreateInstance = &create_monodata;
608     This->ref = 1;
609     This->clsid = *rclsid;
610
611     hr = IClassFactory_QueryInterface( &This->IClassFactory_iface, riid, ppv );
612     IClassFactory_Release(&This->IClassFactory_iface);
613
614     return hr;
615 }
616
617 HRESULT WINAPI DllRegisterServer(void)
618 {
619     return __wine_register_resources( MSCOREE_hInstance );
620 }
621
622 HRESULT WINAPI DllUnregisterServer(void)
623 {
624     return __wine_unregister_resources( MSCOREE_hInstance );
625 }
626
627 HRESULT WINAPI DllCanUnloadNow(VOID)
628 {
629     return S_FALSE;
630 }
631
632 void WINAPI CoEEShutDownCOM(void)
633 {
634     FIXME("stub.\n");
635 }
636
637 INT WINAPI ND_RU1( const void *ptr, INT offset )
638 {
639     return *((const BYTE *)ptr + offset);
640 }
641
642 INT WINAPI ND_RI2( const void *ptr, INT offset )
643 {
644     return *(const SHORT *)((const BYTE *)ptr + offset);
645 }
646
647 INT WINAPI ND_RI4( const void *ptr, INT offset )
648 {
649     return *(const INT *)((const BYTE *)ptr + offset);
650 }
651
652 INT64 WINAPI ND_RI8( const void *ptr, INT offset )
653 {
654     return *(const INT64 *)((const BYTE *)ptr + offset);
655 }
656
657 void WINAPI ND_WU1( void *ptr, INT offset, BYTE val )
658 {
659     *((BYTE *)ptr + offset) = val;
660 }
661
662 void WINAPI ND_WI2( void *ptr, INT offset, SHORT val )
663 {
664     *(SHORT *)((BYTE *)ptr + offset) = val;
665 }
666
667 void WINAPI ND_WI4( void *ptr, INT offset, INT val )
668 {
669     *(INT *)((BYTE *)ptr + offset) = val;
670 }
671
672 void WINAPI ND_WI8( void *ptr, INT offset, INT64 val )
673 {
674     *(INT64 *)((BYTE *)ptr + offset) = val;
675 }
676
677 void WINAPI ND_CopyObjDst( const void *src, void *dst, INT offset, INT size )
678 {
679     memcpy( (BYTE *)dst + offset, src, size );
680 }
681
682 void WINAPI ND_CopyObjSrc( const void *src, INT offset, void *dst, INT size )
683 {
684     memcpy( dst, (const BYTE *)src + offset, size );
685 }