python win下调用dll
小弟接触python 2个星期了,安装的是python3.1版。
我用的是windows7,想写个调用dll的程序实践。问题来了:
C++代码:
extern "C" int __stdcall test();
int __stdcall test()
{
return 1;
}
这个函数是写在.h文件里面的,用vs2005编译成dll。
python代码:
>>> import ctypes
>>> dll = ctypes.WinDLL('C:\\Python31\\libs\\INetWork.dll')
>>> down = dll.test
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
down = dll.test
File "C:\Python31\lib\ctypes\__init__.py", line 363, in __getattr__
func = self.__getitem__(name)
File "C:\Python31\lib\ctypes\__init__.py", line 368, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'test' not found
上网查了下资料有说要吧.dll 改成.pyd ?
我试了下 不管是 改成py 还是pyd都不行 提示的错误都一样。
求大神解惑,不胜感激
[解决办法]
lz 得先确定 DLL 中有 test 这个函数导出
用 depends 之类先看看