Ok, seem to have got it,

I need to change function signature in the DLL to be pointers instead of go 
objects.
Ex.
```
//export Run1
func Run1(ptext *byte) (stdout []byte, stderr []byte, err error) {
          text := windows.BytePtrToString(ptext)
         fmt.Println(text)
return nil, nil, nil
}
```
Weird but ok...

Le mercredi 19 mars 2025 à 00:20:02 UTC+1, rudeus greyrat a écrit :

> I have a DLL compiled with CGO. It exports 3 functions:
>
> ```
> //export Run1
> func Run(text string) (stdout []byte, stderr []byte, err error) {
> fmt.Println(text)
> return nil, nil, nil
> }
>
> //export Run2
> func Run2() (stdout []byte, stderr []byte, err error) {
>        fmt.Println("Heyyyyy")
>         fmt.Println(111111)
> return nil, nil, nil
> }
>
> //export Run3
> func Run3(a int) (stdout []byte, stderr []byte, err error) {
>         fmt.Println(a)
> return nil, nil, nil
> }
> ```
>
>
> In a seperate Go file I import the DLL and try to call the exported 
> function.
> For Run2 everything works
>
> ```
> s = uinptr(ADDRESS_RUN2)
> syscall.SyscallN(s)
> ```
>
> It prints Heyyyyy and 1111111 in my output
>
>
> For Run3, I am not sure how to pass the argument to SyscallN.
> ```
>    
>     s = uinptr(ADDRESS_RUN3)
>     a := 999999999
>     syscall.SyscallN(s, uintptr(unsafe.Pointer(&a)))  ----> Fail (random 
> Number printed)
>
>     a := 999999999
>     syscall.SyscallN(s, uintptr(unsafe.Pointer(a)))  -----> Fail (random 
> Number printed)
>
> ```
>
> For Run1, it get worse as sometimes I get C0000005 error as I use the 
> string elsewhere:
> ```
>         s = uinptr(ADDRESS_RUN1)
>
> cmdBytes := []byte(torun)
> cmdBytes = append(cmdBytes, 0)
> ptr := unsafe.Pointer(&cmdBytes[0])
>         syscall.SyscallN(d, uintptr(ptr))
> ```
>
> Any help please ??
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/ebb86fa9-bc9d-405b-aff8-4637201c5b55n%40googlegroups.com.

Reply via email to