Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_dylib_path() on Windows #7

Merged
merged 4 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>", "Moritz Moeller <[email protected]>"]
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)
}