FAQ
The correct value of exported variables in a DLL cannot be obtained if it
is got directly from cgo. (The example code is in the attachment.) There
are no warnings given, and the program crashes for invalid pointers.
Finally I found a workaround that a wrapper written in C will be able to
get the correct variable value.

// Correct!
fmt.Println(C.getVar(), C.GoString(C.getVar().name))
C.foo(C.getVar())

// Wrong!
fmt.Println(C.exported_var, C.GoString(C.exported_var.name))
C.foo(&C.exported_var) // Crash!

The environment I'm using:
Windows 7 (64 bit)
Mingw-w64 (gcc 4.7.1)
Go 1.0.3 (64 bit)

Hǎiliàng

--

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 2, '12 at 3:52p
activeNov 2, '12 at 3:52p
posts1
users1
websitegolang.org

1 user in discussion

Hǎiliàng: 1 post

People

Translate

site design / logo © 2021 Grokbase