Skip to content

Commit 128551e

Browse files
Clarify Example section and Dl* windows equivalents (ebitengine#274)
1 parent f8c7742 commit 128551e

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ except for float arguments and return values.
3535

3636
## Example
3737

38-
This example only works on macOS and Linux. For a complete example look at [libc](https://github.com/ebitengine/purego/tree/main/examples/libc) which supports Windows and FreeBSD.
38+
The example below only showcases purego use for macOS and Linux. The other platforms require special handling which can
39+
be seen in the complete example at [examples/libc](https://github.com/ebitengine/purego/tree/main/examples/libc) which supports Windows and FreeBSD.
3940

4041
```go
4142
package main

dlerror.go

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
package purego
77

88
// Dlerror represents an error value returned from Dlopen, Dlsym, or Dlclose.
9+
//
10+
// This type is not available on Windows as there is no counterpart to it on Windows.
911
type Dlerror struct {
1012
s string
1113
}

dlfcn.go

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ func init() {
3333
// A second call to Dlopen with the same path will return the same handle, but the internal
3434
// reference count for the handle will be incremented. Therefore, all
3535
// Dlopen calls should be balanced with a Dlclose call.
36+
//
37+
// This function is not available on Windows.
38+
// Use [golang.org/x/sys/windows.LoadLibrary], [golang.org/x/sys/windows.NewLazyDLL], or
39+
// [golang.org/x/sys/windows.NewLazySystemDLL] for Windows instead.
3640
func Dlopen(path string, mode int) (uintptr, error) {
3741
u := fnDlopen(path, mode)
3842
if u == 0 {
@@ -45,6 +49,9 @@ func Dlopen(path string, mode int) (uintptr, error) {
4549
// It returns the address where that symbol is loaded into memory. If the symbol is not found,
4650
// in the specified library or any of the libraries that were automatically loaded by Dlopen
4751
// when that library was loaded, Dlsym returns zero.
52+
//
53+
// This function is not available on Windows.
54+
// Use [golang.org/x/sys/windows.GetProcAddress] for Windows instead.
4855
func Dlsym(handle uintptr, name string) (uintptr, error) {
4956
u := fnDlsym(handle, name)
5057
if u == 0 {
@@ -56,6 +63,9 @@ func Dlsym(handle uintptr, name string) (uintptr, error) {
5663
// Dlclose decrements the reference count on the dynamic library handle.
5764
// If the reference count drops to zero and no other loaded libraries
5865
// use symbols in it, then the dynamic library is unloaded.
66+
//
67+
// This function is not available on Windows.
68+
// Use [golang.org/x/sys/windows.FreeLibrary] for Windows instead.
5969
func Dlclose(handle uintptr) error {
6070
if fnDlclose(handle) {
6171
return Dlerror{fnDlerror()}

0 commit comments

Comments
 (0)