Re: [go-nuts] [CGO] How can I convert GoString to wchar_t?

2020-09-26 Thread Jan Mercl
On Sat, Sep 26, 2020 at 10:01 PM Raffaele Sena  wrote:
>
> wchar_t is a 16 bits value representing a UTF16 character so you could 
> convert Go strings to and from UTF16 using the unicode/utf16 package.

FTR: Correct for Windows, may be different on other platforms.

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-XN296Ngqe6Rwa3rdNVTQeZ9nTQdu8v8zFw7reyh3Vupg%40mail.gmail.com.


Re: [go-nuts] [CGO] How can I convert GoString to wchar_t?

2020-09-26 Thread Raffaele Sena
wchar_t is a 16 bits value representing a UTF16 character so you could
convert Go strings to and from UTF16 using the unicode/utf16 package.


On Sat, Sep 26, 2020 at 11:39 AM Sean  wrote:

> Hi gophers,
>
> I'm trying to write the Golang wrapper for a dll with CGO.
>
> A wrapper that will only work in windows.
>
> I need to be able to send UTF-8 or unicode strings to c.
>
> This issue was never asked on platforms like stackoverflow.
>
> So I couldn't find a solution.
>
> https://github.com/dkager/tolk/blob/master/src/Tolk.h#l72
> line 72
>
> https://github.com/dkager/tolk/blob/master/src/Tolk.h#l100
> line 100
>
> I am adding the code I tried below:
>
>
> package talker
>
> //#cgo windows  CFLAGS: -DGO_WINDOWS -Iinclude
> //#cgo windows  LDFLAGS: -Llib/x64 -lTolk
> //#include "Tolk.h"
> import "C"
> //  import "unsafe"
>
>
> func Load() {
> C.Tolk_Load()
> }
>
> func IsLoaded() bool {
> if C.Tolk_IsLoaded() == false {
> return false
> }
> return true
> }
>
>
> func Unload() {
> C.Tolk_Unload()
> }
>
>
> // problem: the function I can't find a solution for.
> func DetectScreenReader() string{
> return C.GoString(C.Tolk_DetectScreenReader())
> }
>
> func HasBraille() bool{
> b := C.Tolk_HasBraille()
> if (b == false) {
> return false }
> return true
> }
>
> // problem: the second function I can't find a solution for ..
> func Output(text string, interrupt bool) {
> b := C.bool(bool)
> C.Tolk_Output((*C.wchar_t)(text), b)
> }
>
>
>
> error: .\talker.go:39:28: cannot convert text (type string) to type
> *_Ctype_ushort
>
> Sean
>
>- Email: seantolstoyev...@protonmail.com
>
>- GitHub: SeanTolstoyevski 
>
> ‍羚 I’m a software developer. I coding often Python, sometimes Go and
> rarely (C)/C++.
>
> --
> 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 on the web visit
> https://groups.google.com/d/msgid/golang-nuts/aeaba06b-bb41-3e3a-3ee4-7993b8bb4596%40gmail.com
> 
> .
>

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANKfucbP61nRLwsca1UsQSYq6qq-mMC-ZC8i6mHEGKqra72eAQ%40mail.gmail.com.


[go-nuts] [CGO] How can I convert GoString to wchar_t?

2020-09-26 Thread Sean

Hi gophers,

I'm trying to write the Golang wrapper for a dll with CGO.

A wrapper that will only work in windows.

I need to be able to send UTF-8 or unicode strings to c.

This issue was never asked on platforms like stackoverflow.

So I couldn't find a solution.

https://github.com/dkager/tolk/blob/master/src/Tolk.h#l72
line 72

https://github.com/dkager/tolk/blob/master/src/Tolk.h#l100
line 100

I am adding the code I tried below:


package talker

//#cgo windows  CFLAGS: -DGO_WINDOWS -Iinclude
//#cgo windows  LDFLAGS: -Llib/x64 -lTolk
//#include "Tolk.h"
import "C"
//  import "unsafe"


func Load() {
    C.Tolk_Load()
}

func IsLoaded() bool {
    if C.Tolk_IsLoaded() == false {
        return false
        }
    return true
}


func Unload() {
    C.Tolk_Unload()
}


// problem: the function I can't find a solution for.
func DetectScreenReader() string{
    return C.GoString(C.Tolk_DetectScreenReader())
}

func HasBraille() bool{
    b := C.Tolk_HasBraille()
    if (b == false) {
        return false }
    return true
}

// problem: the second function I can't find a solution for ..
func Output(text string, interrupt bool) {
    b := C.bool(bool)
    C.Tolk_Output((*C.wchar_t)(text), b)
}



error: .\talker.go:39:28: cannot convert text (type string) to type 
*_Ctype_ushort



Sean

 * Email: seantolstoyev...@protonmail.com
   
 * GitHub: SeanTolstoyevski 

‍羚 I’m a software developer. I coding often Python, sometimes Go and 
rarely (C)/C++.


--
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/aeaba06b-bb41-3e3a-3ee4-7993b8bb4596%40gmail.com.