今天研究了AllenDang(博客:http://www.cnblogs.com/AllenDang) 写的gform(一个go语言的windows图形库),也顺便学习了如何调用window的dll库。这里用C写了一个简单的功能函数gcd,然后编译打包成dll库。最后,写了一个go的调用例子hello.go。hello.go里面加载dll库,并调用gcd函数获取返回结果。 注意:为了运行例子,需要已经安装好MinGW和go. [@more@]
1、 C写的简单例子。
/* File : example2.c */
/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
int g;
g = y;
while (x > 0) {
g = x;
x = y % x;
y = g;
}
return g;
}
2、 编译dll