运行结果
go代码
package main
import (
"fmt"
"syscall"
"unsafe"
)
func main() {
test := syscall.NewLazyDLL("Win32Project1.dll")
add := test.NewProc("add")
outRand := make([]byte, 2)
a := 1
b := 2
sum, _, _ := add.Call(uintptr(a), uintptr(b), uintptr(unsafe.Pointer(&outRand[0])))
fmt.Printf("sum:%d\noutRand:%s\n", sum, outRand)
}
c++代码(.cpp)
#include "Win32Project1.h"
#include "stdafx.h"
int _stdcall add(int a, int b,char* c) {
*c ='e' ;
*(c + 1) = 't';
return a + b;
}
c++代码(.h)
extern _declspec(dllexport) int _stdcall add(int a,int b);
c++代码(.def)
LIBRARY Win32Project1
EXPORTS
add @ 1
网友评论