Caling windows DLL func from go :: parameter is incorrect

348 views
Skip to first unread message

amit....@gmail.com

unread,
Aug 4, 2018, 12:18:18 AM8/4/18
to golang-nuts
I am trying to call a DLL from go and I get an error "The parameter is incorrect" error when I try to call this function 

HANDLE  Myopen(const char *filter, LAYER layer, INT16 priority, UINT64 flags)

is my signature in the C file 

I call from golang using this 

Open(lazyP*syscall.LazyProc, filter string, layer int16, priority uint16, flags uint64) error {
 r1, r2, lastError := lazyP.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(filter))),
  uintptr(layer),
  uintptr(priority),
  uintptr(flags),
 )

 fmt.Println("LastError", lastError)

 fmt.Println("R1", r1)

 fmt.Println("R2", r2)

 return nil
}

What am I missing here. This is the first time I am trying to load windows dlls so a little confused about what am I missing here 


Regards
Amit


Tamás Gulácsi

unread,
Aug 4, 2018, 1:58:22 AM8/4/18
to golang-nuts
What is LAYER?
is priority an int16 or an uint16?

Oryan Moshe

unread,
Aug 4, 2018, 1:53:40 PM8/4/18
to amit....@gmail.com, golang-nuts
Seems to me like type issues as well, doesn't seem like it for winapi to receive int16. 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

amit....@gmail.com

unread,
Aug 6, 2018, 11:33:37 AM8/6/18
to golang-nuts
layer is an enum in the dll. 
Gets converted to uint32 inside the dll before it makes the windows api call. 
priority is exposed as int16 in the exported dll api 

Regards
Amit

Amit Limaye

unread,
Aug 6, 2018, 11:46:52 AM8/6/18
to golan...@googlegroups.com
is the const char * a problem my string is not passed as const ?
-SIGTERM
amit

Humanity's first sin was faith, Its first virtue doubt
> You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/o1epszOy544/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.

Oryan Moshe

unread,
Aug 6, 2018, 11:50:10 AM8/6/18
to Amit Limaye, golan...@googlegroups.com
It doesn't look like you turn it to const anywhere, just a pointer. Is the pointer conversion returning a const? 

Amit Limaye

unread,
Aug 6, 2018, 11:54:25 AM8/6/18
to iamory...@gmail.com, golan...@googlegroups.com
the dll exported function signature takes a const char *
while I am passing a string
my golang call signature

Open(lazyP*syscall.LazyProc, filter string, layer uint32, priority
int16, flags uint64) error

which I use to make this call
r1, r2, lastError :=
lazyP.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(filter))),
uintptr(layer),
uintptr(priority),
uintptr(flags),
)

and my dll exported func signature is

HANDLE Open(const char *filter,DIVERT_LAYER layer,
INT16 priority, UINT64 flags)


-SIGTERM
amit

Humanity's first sin was faith, Its first virtue doubt

Oryan Moshe

unread,
Aug 6, 2018, 11:58:32 AM8/6/18
to Amit Limaye, golan...@googlegroups.com
Can you try casting your string to a c char? 
(*C.char)(unsafe.Pointer(string))
Reply all
Reply to author
Forward
0 new messages