1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4//
5// File: NativeLibraryNative.cpp
6//
7
8#include "common.h"
9#include "dllimport.h"
10#include "nativelibrarynative.h"
11
12// static
13INT_PTR QCALLTYPE NativeLibraryNative::LoadFromPath(LPCWSTR path, BOOL throwOnError)
14{
15 QCALL_CONTRACT;
16
17 NATIVE_LIBRARY_HANDLE handle = nullptr;
18
19 BEGIN_QCALL;
20
21 handle = NDirect::LoadLibraryFromPath(path, throwOnError);
22
23 END_QCALL;
24
25 return reinterpret_cast<INT_PTR>(handle);
26}
27
28// static
29INT_PTR QCALLTYPE NativeLibraryNative::LoadByName(LPCWSTR name, QCall::AssemblyHandle callingAssembly,
30 BOOL hasDllImportSearchPathFlag, DWORD dllImportSearchPathFlag,
31 BOOL throwOnError)
32{
33 QCALL_CONTRACT;
34
35 NATIVE_LIBRARY_HANDLE handle = nullptr;
36 Assembly *pAssembly = callingAssembly->GetAssembly();
37
38 BEGIN_QCALL;
39
40 handle = NDirect::LoadLibraryByName(name, pAssembly, hasDllImportSearchPathFlag, dllImportSearchPathFlag, throwOnError);
41
42 END_QCALL;
43
44 return reinterpret_cast<INT_PTR>(handle);
45}
46
47// static
48void QCALLTYPE NativeLibraryNative::FreeLib(INT_PTR handle)
49{
50 QCALL_CONTRACT;
51
52 BEGIN_QCALL;
53
54 NDirect::FreeNativeLibrary((NATIVE_LIBRARY_HANDLE) handle);
55
56 END_QCALL;
57}
58
59//static
60INT_PTR QCALLTYPE NativeLibraryNative::GetSymbol(INT_PTR handle, LPCWSTR symbolName, BOOL throwOnError)
61{
62 QCALL_CONTRACT;
63
64 INT_PTR address = NULL;
65
66 BEGIN_QCALL;
67
68 address = NDirect::GetNativeLibraryExport((NATIVE_LIBRARY_HANDLE)handle, symbolName, throwOnError);
69
70 END_QCALL;
71
72 return address;
73}
74
75