@@ -34,6 +34,11 @@ like func declarations if //sys is replaced by func, but:
34
34
- If the function name ends in a "?", then the function not existing is non-
35
35
fatal, and an error will be returned instead of panicking.
36
36
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
+
37
42
Usage:
38
43
39
44
mkwinsyscall [flags] [path ...]
@@ -359,13 +364,14 @@ func (r *Rets) SetErrorCode() string {
359
364
360
365
// Fn describes syscall function.
361
366
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
369
375
// TODO: get rid of this field and just use parameter index instead
370
376
curTmpVarIdx int // insure tmp variables have uniq names
371
377
}
@@ -471,6 +477,13 @@ func newFn(s string) (*Fn, error) {
471
477
if found {
472
478
f .Rets .FailCond = body
473
479
}
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
+ }
474
487
// dll and dll function names
475
488
s = trim (s )
476
489
if s == "" {
@@ -499,9 +512,12 @@ func newFn(s string) (*Fn, error) {
499
512
// DLLName returns DLL name for function f.
500
513
func (f * Fn ) DLLName () string {
501
514
if f .dllname == "" {
502
- return "kernel32"
515
+ return "kernel32.dll"
516
+ }
517
+ if f .dllExtension != "" {
518
+ return f .dllname + "." + f .dllExtension
503
519
}
504
- return f .dllname
520
+ return f .dllname + ".dll"
505
521
}
506
522
507
523
// DLLVar returns a valid Go identifier that represents DLLName.
@@ -849,7 +865,7 @@ func (src *Source) Generate(w io.Writer) error {
849
865
"packagename" : packagename ,
850
866
"syscalldot" : syscalldot ,
851
867
"newlazydll" : func (dll string ) string {
852
- arg := "\" " + dll + ".dll \" "
868
+ arg := "\" " + dll + "\" "
853
869
if ! * systemDLL {
854
870
return syscalldot () + "NewLazyDLL(" + arg + ")"
855
871
}
0 commit comments