summaryrefslogtreecommitdiff
path: root/src/vm/nativelibrarynative.cpp
blob: c5bf24f06e65c36d2b165c85e5b5e4b6cdb3bc07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// 
// File: NativeLibraryNative.cpp
//

#include "common.h"
#include "dllimport.h"
#include "nativelibrarynative.h"

// static
INT_PTR QCALLTYPE NativeLibraryNative::LoadFromPath(LPCWSTR path, BOOL throwOnError)
{
    QCALL_CONTRACT;

    NATIVE_LIBRARY_HANDLE handle = nullptr;

    BEGIN_QCALL;

    handle = NDirect::LoadLibraryFromPath(path, throwOnError);

    END_QCALL;

    return reinterpret_cast<INT_PTR>(handle);
}

// static
INT_PTR QCALLTYPE NativeLibraryNative::LoadByName(LPCWSTR name, QCall::AssemblyHandle callingAssembly,
                                                         BOOL hasDllImportSearchPathFlag, DWORD dllImportSearchPathFlag, 
                                                         BOOL throwOnError)
{
    QCALL_CONTRACT;

    NATIVE_LIBRARY_HANDLE handle = nullptr;
    Assembly *pAssembly = callingAssembly->GetAssembly();

    BEGIN_QCALL;

    handle = NDirect::LoadLibraryByName(name, pAssembly, hasDllImportSearchPathFlag, dllImportSearchPathFlag, throwOnError);

    END_QCALL;

    return reinterpret_cast<INT_PTR>(handle);
}

// static
void QCALLTYPE NativeLibraryNative::FreeLib(INT_PTR handle)
{
    QCALL_CONTRACT;

    BEGIN_QCALL;

    NDirect::FreeNativeLibrary((NATIVE_LIBRARY_HANDLE) handle);
    
    END_QCALL;
}

//static 
INT_PTR QCALLTYPE NativeLibraryNative::GetSymbol(INT_PTR handle, LPCWSTR symbolName, BOOL throwOnError)
{
    QCALL_CONTRACT;

    INT_PTR address = NULL;
    
    BEGIN_QCALL;

    address = NDirect::GetNativeLibraryExport((NATIVE_LIBRARY_HANDLE)handle, symbolName, throwOnError);

    END_QCALL;

    return address;
}