标签:style blog http java color os
一。利用Ctypes
2014-04-29
EXAMPLE:
//VS2012,新建WINDOWS Project ,下一步,选择dll
// test.h #include<iostream> extern "C" int __declspec(dllexport)add(int x,int y); // .cpp #include "test.h" int __declspec(dllexport)add(int x,int y) { //std::cout<<x<<" "<<y<<std::endl; std::cout<<x+y<<std::endl; return x+y; }
编译平台为X64(因为我的python为64位)
import ctypes ll=ctypes.cdll.LoadLibrary lib=ll(r"D:\VSProjects\pyc1\x64\Debug\pyc1.dll") lib.add(1,3)
调用成功
问题注意:
1.python为64位,必须导入64位的dll,否则会发生win32错误
2.路径在windows下为D:\\。。。等等
标签:style blog http java color os
原文地址:http://www.cnblogs.com/karcylee/p/3698864.html