Skip to content

Commit a428f66

Browse files
committed
windows: in mkwinsyscall, add an option to specify a custom dll extension
The current implementation uses a hardcoded '.dll' extension, but some Windows dll files have different extensions (such as .ocx, .drv). Fixes #58337
1 parent e0c3b6e commit a428f66

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

windows/mkwinsyscall/mkwinsyscall.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ like func declarations if //sys is replaced by func, but:
3434
- If the function name ends in a "?", then the function not existing is non-
3535
fatal, and an error will be returned instead of panicking.
3636
37+
- By default, the extension used for the dll is '.dll'. If the dll name needs to
38+
end with a custom extension, it can be specified at the end of //sys declaration, like
39+
//sys LoadLibrary(libname string) (handle uint32, err error) = LoadLibraryA [ext=drv]
40+
This will cause the generated code to have 'LoadLibraryA.drv' instead of 'LoadLibraryA.dll'
41+
3742
Usage:
3843
3944
mkwinsyscall [flags] [path ...]
@@ -359,13 +364,14 @@ func (r *Rets) SetErrorCode() string {
359364

360365
// Fn describes syscall function.
361366
type Fn struct {
362-
Name string
363-
Params []*Param
364-
Rets *Rets
365-
PrintTrace bool
366-
dllname string
367-
dllfuncname string
368-
src string
367+
Name string
368+
Params []*Param
369+
Rets *Rets
370+
PrintTrace bool
371+
dllname string
372+
dllExtension string
373+
dllfuncname string
374+
src string
369375
// TODO: get rid of this field and just use parameter index instead
370376
curTmpVarIdx int // insure tmp variables have uniq names
371377
}
@@ -471,6 +477,13 @@ func newFn(s string) (*Fn, error) {
471477
if found {
472478
f.Rets.FailCond = body
473479
}
480+
// custom dll extension
481+
prefix, body, _, found = extractSection(s, '[', ']')
482+
if found {
483+
ext := strings.Replace(strings.ReplaceAll(body, " ", ""), "ext=", "", 1)
484+
f.dllExtension = trim(ext)
485+
s = prefix
486+
}
474487
// dll and dll function names
475488
s = trim(s)
476489
if s == "" {
@@ -499,9 +512,12 @@ func newFn(s string) (*Fn, error) {
499512
// DLLName returns DLL name for function f.
500513
func (f *Fn) DLLName() string {
501514
if f.dllname == "" {
502-
return "kernel32"
515+
return "kernel32.dll"
516+
}
517+
if f.dllExtension != "" {
518+
return f.dllname + "." + f.dllExtension
503519
}
504-
return f.dllname
520+
return f.dllname + ".dll"
505521
}
506522

507523
// DLLVar returns a valid Go identifier that represents DLLName.
@@ -849,7 +865,7 @@ func (src *Source) Generate(w io.Writer) error {
849865
"packagename": packagename,
850866
"syscalldot": syscalldot,
851867
"newlazydll": func(dll string) string {
852-
arg := "\"" + dll + ".dll\""
868+
arg := "\"" + dll + "\""
853869
if !*systemDLL {
854870
return syscalldot() + "NewLazyDLL(" + arg + ")"
855871
}

0 commit comments

Comments
 (0)