summaryrefslogtreecommitdiff
path: root/misc/cgo/testso/cgoso_c.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/cgo/testso/cgoso_c.c')
-rw-r--r--misc/cgo/testso/cgoso_c.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/misc/cgo/testso/cgoso_c.c b/misc/cgo/testso/cgoso_c.c
index 8c15a6b9f..27155c27f 100644
--- a/misc/cgo/testso/cgoso_c.c
+++ b/misc/cgo/testso/cgoso_c.c
@@ -4,8 +4,22 @@
// +build ignore
+#ifdef WIN32
+// A Windows DLL is unable to call an arbitrary function in
+// the main executable. Work around that by making the main
+// executable pass the callback function pointer to us.
+void (*goCallback)(void);
+__declspec(dllexport) void setCallback(void *f)
+{
+ goCallback = (void (*)())f;
+}
+__declspec(dllexport) void sofunc(void);
+#else
+extern void goCallback(void);
+void setCallback(void *f) { (void)f; }
+#endif
+
void sofunc(void)
{
- extern void goCallback(void);
goCallback();
}