Skip to content

Commit

Permalink
Merge pull request #7 from talagrand/talagrand/win-dylib-path
Browse files Browse the repository at this point in the history
Fix get_dylib_path() on Windows
  • Loading branch information
wesleywiser authored Apr 26, 2021
2 parents 63add3a + ca85588 commit 33c2bdb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "process_path"
version = "0.1.3"
version = "0.1.4"
authors = ["Wesley Wiser <wwiser@gmail.com>", "Moritz Moeller <virtualritz@gmail.com>"]
license = "MIT/Apache-2.0"
repository = "https://github.com/wesleywiser/process_path"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ library in the file system.
Add this to your `Cargo.toml`:
```toml
[dependencies]
process_path = "0.1.3"
process_path = "0.1.4"
```
and this to your crate root:
```rust
Expand Down
15 changes: 8 additions & 7 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use std::ffi::OsString;
use std::os::windows::ffi::OsStringExt;
use std::path::PathBuf;
use std::ptr;
use winapi::shared::minwindef::DWORD;
use winapi::shared::minwindef::{DWORD, MAX_PATH};
use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER;
use winapi::um::{
errhandlingapi::GetLastError,
libloaderapi::{
GetModuleFileNameW, GetModuleHandleExW, GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
GetModuleFileNameW, GetModuleHandleExW, GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
}
},
};
use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER;

pub(crate) fn get_executable_path() -> Option<PathBuf> {
fn get_executable_path(len: usize) -> Option<PathBuf> {
Expand All @@ -36,7 +36,7 @@ pub(crate) fn get_executable_path() -> Option<PathBuf> {
}
}

get_executable_path(256)
get_executable_path(MAX_PATH)
}

pub(crate) fn get_dylib_path() -> Option<PathBuf> {
Expand All @@ -49,7 +49,8 @@ pub(crate) fn get_dylib_path() -> Option<PathBuf> {
| GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
get_dylib_path as *const _,
&mut handle_module,
) != 0 {
) == 0
{
None
} else {
let ret =
Expand All @@ -74,5 +75,5 @@ pub(crate) fn get_dylib_path() -> Option<PathBuf> {
}
}

get_dylib_path(256)
get_dylib_path(MAX_PATH)
}

0 comments on commit 33c2bdb

Please sign in to comment.