DLL中导出的C函数
static const char* s_ptr="asdf"
extern "C" _declspec (dllexport) char* TestString(char** ppChar, int* plen) {
wchar_t wp[] = {L"测试中文啊aahahah哈哈哈"};
static std::string ap = WToX(wp, CP_UTF8);
return (char*)s_ptr;
}
GO加载DLL并获得返回值
package main
import "C" 必须要有
lib := syscall.NewLazyDLL("winfunc.dll")
testString := lib.NewProc("TestString")
var p1 uintptr
var p2 uintptr
testString.Call(uintptr(unsafe.Pointer(&p1)), uintptr(unsafe.Pointer(&p2))) GO里面都是转换为uintptr形式传递到C的,所以这里直接定义两个uinptr变量即可,后面在进行类型转换
m111 := (*C.char)(unsafe.Pointer(p1))
println(m111)
s := C.GoString(m111)
println(s)