Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
native_library_win.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/fml/native_library.h"
6
7#include <windows.h>
8
9#include "flutter/fml/platform/win/wstring_conversion.h"
10
11namespace fml {
12
13NativeLibrary::NativeLibrary(const char* path)
14 : handle_(nullptr), close_handle_(true) {
15 if (path == nullptr) {
16 return;
17 }
18
19 handle_ = ::LoadLibrary(Utf8ToWideString(path).c_str());
20}
21
22NativeLibrary::NativeLibrary(Handle handle, bool close_handle)
23 : handle_(handle), close_handle_(close_handle) {}
24
25NativeLibrary::~NativeLibrary() {
26 if (handle_ != nullptr && close_handle_) {
27 ::FreeLibrary(handle_);
28 }
29}
30
31NativeLibrary::Handle NativeLibrary::GetHandle() const {
32 return handle_;
33}
34
35fml::RefPtr<NativeLibrary> NativeLibrary::Create(const char* path) {
36 auto library = fml::AdoptRef(new NativeLibrary(path));
37 return library->GetHandle() != nullptr ? library : nullptr;
38}
39
40fml::RefPtr<NativeLibrary> NativeLibrary::CreateWithHandle(
41 Handle handle,
42 bool close_handle_when_done) {
43 auto library =
44 fml::AdoptRef(new NativeLibrary(handle, close_handle_when_done));
45 return library->GetHandle() != nullptr ? library : nullptr;
46}
47
48fml::RefPtr<NativeLibrary> NativeLibrary::CreateForCurrentProcess() {
49 return fml::AdoptRef(new NativeLibrary(::GetModuleHandle(nullptr), false));
50}
51
52NativeLibrary::SymbolHandle NativeLibrary::Resolve(const char* symbol) const {
53 if (symbol == nullptr || handle_ == nullptr) {
54 return nullptr;
55 }
56 return ::GetProcAddress(handle_, symbol);
57}
58
59} // namespace fml
std::wstring Utf8ToWideString(const std::string_view str)
RefPtr< T > AdoptRef(T *ptr)
Definition ref_ptr.h:222
fuchsia::ui::composition::ParentViewportWatcherHandle handle_