Go 调用dll

运行结果

《Go 调用dll》

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
    原文作者:tpkeeper
    原文地址: https://www.jianshu.com/p/632ffea266f3
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞