Flutter Engine
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 
11 namespace fml {
12 
13 NativeLibrary::NativeLibrary(const char* path)
14  : handle_(nullptr), close_handle_(true) {
15  if (path == nullptr) {
16  return;
17  }
18 
19  handle_ = ::LoadLibrary(StringToWideString(path).c_str());
20 }
21 
22 NativeLibrary::NativeLibrary(Handle handle, bool close_handle)
23  : handle_(handle), close_handle_(close_handle) {}
24 
25 NativeLibrary::~NativeLibrary() {
26  if (handle_ != nullptr && close_handle_) {
27  ::FreeLibrary(handle_);
28  }
29 }
30 
31 NativeLibrary::Handle NativeLibrary::GetHandle() const {
32  return handle_;
33 }
34 
36  auto library = fml::AdoptRef(new NativeLibrary(path));
37  return library->GetHandle() != nullptr ? library : nullptr;
38 }
39 
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 
49  return fml::AdoptRef(new NativeLibrary(::GetModuleHandle(nullptr), false));
50 }
51 
52 const uint8_t* NativeLibrary::ResolveSymbol(const char* symbol) {
53  if (symbol == nullptr || handle_ == nullptr) {
54  return nullptr;
55  }
56  return reinterpret_cast<const uint8_t*>(::GetProcAddress(handle_, symbol));
57 }
58 
59 } // namespace fml
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
static fml::RefPtr< NativeLibrary > CreateForCurrentProcess()
static fml::RefPtr< NativeLibrary > CreateWithHandle(Handle handle, bool close_handle_when_done)
Definition: ascii_trie.cc:9
static fml::RefPtr< NativeLibrary > Create(const char *path)
RefPtr< T > AdoptRef(T *ptr)
Definition: ref_ptr.h:218
std::wstring StringToWideString(const std::string &str)
const uint8_t * ResolveSymbol(const char *symbol)