Skip to content

Commit c2f2208

Browse files
Added NSTDWindowsSharedLibHandle.
1 parent 1197a34 commit c2f2208

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
### `nstd.fs`
1919
- Added `NSTDFileResult`.
2020
### `nstd.os`
21+
- Added `NSTDWindowsSharedLibHandle`.
2122
- Added `unix.alloc`.
2223
- Added `[unix|windows].shared_lib`.
2324
- Added `NSTDWindowsHeapResult`.

include/nstd/os/windows/shared_lib.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
#include "../../core/optional.h"
44
#include "../../nstd.h"
55

6+
/// A raw handle to a dynamically loaded library.
7+
typedef NSTDInt NSTDWindowsSharedLibHandle;
8+
69
/// A handle to a loaded library.
710
typedef struct {
811
/// A raw handle to the module.
9-
NSTDInt handle;
12+
NSTDWindowsSharedLibHandle handle;
1013
} NSTDWindowsSharedLib;
1114

1215
/// An optional (possibly null) shared Windows library handle.
@@ -28,6 +31,18 @@ NSTDOptional(NSTDWindowsSharedLib) NSTDWindowsOptionalSharedLib;
2831
/// <https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibrarya>.
2932
NSTDAPI NSTDWindowsOptionalSharedLib nstd_os_windows_shared_lib_load(const NSTDChar *name);
3033

34+
/// Returns a raw handle to a dynamically loaded library.
35+
///
36+
/// # Parameters:
37+
///
38+
/// - `const NSTDWindowsSharedLib *lib` - The loaded library.
39+
///
40+
/// # Returns
41+
///
42+
/// `NSTDWindowsSharedLibHandle handle` - A native handle to the dynamically loaded library.
43+
NSTDAPI NSTDWindowsSharedLibHandle nstd_os_windows_shared_lib_handle(
44+
const NSTDWindowsSharedLib *lib);
45+
3146
/// Gets a pointer to a function or static variable in a dynamically loaded library by symbol name.
3247
///
3348
/// # Parameters

src/os/windows/shared_lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
use crate::{core::optional::NSTDOptional, NSTDAny, NSTDAnyMut, NSTDChar, NSTDInt};
33
use windows_sys::Win32::System::LibraryLoader::{FreeLibrary, GetProcAddress, LoadLibraryA};
44

5+
/// A raw handle to a dynamically loaded library.
6+
pub type NSTDWindowsSharedLibHandle = NSTDInt;
7+
58
/// A handle to a loaded library.
69
#[repr(C)]
710
pub struct NSTDWindowsSharedLib {
811
/// A raw handle to the module.
9-
handle: NSTDInt,
12+
handle: NSTDWindowsSharedLibHandle,
1013
}
1114
impl Drop for NSTDWindowsSharedLib {
1215
/// [NSTDWindowsSharedLib]'s destructor.
@@ -45,6 +48,23 @@ pub unsafe extern "C" fn nstd_os_windows_shared_lib_load(
4548
}
4649
}
4750

51+
/// Returns a raw handle to a dynamically loaded library.
52+
///
53+
/// # Parameters:
54+
///
55+
/// - `const NSTDWindowsSharedLib *lib` - The loaded library.
56+
///
57+
/// # Returns
58+
///
59+
/// `NSTDWindowsSharedLibHandle handle` - A native handle to the dynamically loaded library.
60+
#[inline]
61+
#[cfg_attr(feature = "clib", no_mangle)]
62+
pub extern "C" fn nstd_os_windows_shared_lib_handle(
63+
lib: &NSTDWindowsSharedLib,
64+
) -> NSTDWindowsSharedLibHandle {
65+
lib.handle
66+
}
67+
4868
/// Gets a pointer to a function or static variable in a dynamically loaded library by symbol name.
4969
///
5070
/// # Parameters

0 commit comments

Comments
 (0)